I'm trying to dynamically create methods depending on provided name like page-object gem do. But In my case c.custom =
just returning passed argument, like simple assignment.
In my original task I need to send method call with provided value like:
self.send(method).send_keys(value)
Also, I notice, when added puts
to line "called #{name} with #{value}"
and called custom
from outside of object like C.new.custom = 123
it will produce expected output, but still that's not what I want.
Is there any way to define required method, to call it inside and outside of object?
module M
def create(name)
define_method("#{name}=") do |value|
"called #{name} with #{value}"
end
end
end
class C
extend M
create(:custom)
def initialize(val)
puts custom = val
end
end
C.new('haha')