J
Jimmy Soho
Hi All,
I'm looking to do something like:
def test(name, proc)
class_eval(<<-EOS, __FILE__, __LINE__)
def #{name}_string=(str)
# do stuff, whatever
self.#{name} = proc.call(str)
end
EOS
end
and I want to call it like e.g.:
class Project
attr_accessor :due_at
test :due_at, lamdba { |x| Time.parse(x) }
end
and then:
Project.new.due_at_string = "2008-01-01 00:00"
puts Project.new.due_at # should result in a Time object
The problem I'm facing is: how can I call proc from within the
interpolated string that is given to class_eval ?? How should I write
my class_eval differently?
Best regards,
Jimmy
I'm looking to do something like:
def test(name, proc)
class_eval(<<-EOS, __FILE__, __LINE__)
def #{name}_string=(str)
# do stuff, whatever
self.#{name} = proc.call(str)
end
EOS
end
and I want to call it like e.g.:
class Project
attr_accessor :due_at
test :due_at, lamdba { |x| Time.parse(x) }
end
and then:
Project.new.due_at_string = "2008-01-01 00:00"
puts Project.new.due_at # should result in a Time object
The problem I'm facing is: how can I call proc from within the
interpolated string that is given to class_eval ?? How should I write
my class_eval differently?
Best regards,
Jimmy