Elad on Rails
Ruby On Rails and a Conning Israeli entrepreneur
Wednesday, August 29, 2007
Dynamically adding methods
This is divine, ruby is too great to be true. no explanation needed.
class
Object
def
def
(method_name, &block)
(
class
<<
self
;
self
end
).send(
:define_method
, method_name, block)
end
end
x =
Object
.
new
string =
"This is a test"
x.
def
(
:elad_says
) {puts
"Elad says: "
+ string}
x.elad_says
No comments:
Post a Comment
Tell me what you think
‹
›
Home
View web version
No comments:
Post a Comment
Tell me what you think