My functions:
def hello(str) puts "hello #{str}" end def hello_scope(scope, &block)
I would like to temporarily increase the function inside the block of my method.
In hello_scope I just want to add the scope string to str before passing it to the original hello method. Here is an example:
hello 'world'
I'm kind of a noob when it comes to this kind of thing in Ruby. Can someone help me solve this in an elegant way?
Edit:
If this simplifies the work, it is normal if we pass the method as an argument to a block, for example:
hello_scope "welcome!" do |h| h "bob" #=> welcome!hello bob h "alice" #=> welcome!hello alice end
source share