Hi.
I have been playing with the following code (explanation follows after
the code):
require ‘pp’
class Object
def method_missing(*args)
return args.join ’ ’
end
end
def foo(i = nil)
puts i if i
puts yield if block_given?
end
foo
foo ‘testing 1’
foo { ‘testing 2’ }
foo { testing 3 }
The code above returns:
testing 1
testing 2
testing 3
Ok, this code defines method foo, and we use 4 different ways to
call it.
What I was most interested in was the last version - I want to access
all what was passed in a block as string. This is useful for one
project, but it is not good to modify Object in such a way in larger
projects.
Any advice on whether it is possible to keep this piece of code only on
a per-project basis? Like, I want to extend class Object only in the
context of that specific object, but if I use it in a larger project, I
don’t want to use that very modification to class Object (because,
outside that project, it would be counter-productive to act on
method_missing that way).
Edit: Oh well, seems the code above doesn’t work anyway as expected…
can’t seem to pass in stuff like
{ testing gkljejklwe hlkjhjklhhwe }