Hi all,
did anybody think of this?
module Kernel
def with(obj, &blk)
obj.instance_eval &blk
end
end
It's so simple that I barely dare to propose it. Of course, one could use
instance_eval directly, but the keyword is IMHO a bit more intuitive and
it is known from other programming languages. (Pascal, which else?)
Now you can do
anAwfulLongIdentifierThatYouWontLiktToTypeOften = "foo"
with anAwfulLongIdentifierThatYouWontLiktToTypeOften do
puts length
concat "bar"
puts length
puts self
end
What do others think? Is this worthwile to be included in the Ruby std
lib?
Regards
robert
Pascal:
http://www.cs.qub.ac.uk/~S.Fitzpatrick/Teaching/Pascal/EBNF.html#with-statement