Skip to content

Instantly share code, notes, and snippets.

@Irio
Created July 13, 2012 14:02
Show Gist options
  • Save Irio/3105041 to your computer and use it in GitHub Desktop.
Save Irio/3105041 to your computer and use it in GitHub Desktop.
defining class methods
class SinglePages
file :about, %w(text)
class << self
# Generate write method to this file
def file(filename, attrs)
define_method "write_#{filename}" do |properties_hash|
puts properties_hash
end
end
end
end
@Irio
Copy link
Author

Irio commented Jul 13, 2012

SinglePages.new.write_about('teste')

@nicholaspufal
Copy link

class SinglePages
  class << self
    def file(method_name, *args)
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def write_#{method_name}(*args)
          args.each do |arg|
            puts arg
          end
        end
        RUBY
    end
  end

  file :about, %w(teste)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment