I don\'t understand the keywords like attr_reader
or property
in the following example:
class Voiture
attr_reader :name
attr_
That are just class methods. In this example has_foo
adds a foo
method to an instance that puts a string:
module Foo
def has_foo(value)
class_eval <<-END_OF_RUBY, __FILE__, __LINE__ + 1
def foo
puts "#{value}"
end
END_OF_RUBY
end
end
class Baz
extend Foo
has_foo 'Hello World'
end
Baz.new.foo # => Hello World