I have some code that needs to be called directly or passed to another method that must take a block. Pseudocode:
class Foo
def bar
if condition
return method_that_needs_a_block!('string', named1:, named2:) do
shared_method('a', 'b')
end
end
shared_method('a', 'b')
end
def shared_method(arg1, arg2)
puts arg1
puts arg2
end
end
You can see the method that must take a block method_that_needs_a_block
has a string for the first parameter and the rest are named parameters. How can shared_method
be used as either a method or a block and still be able to pass the arguments to it? I've attempted making the method a lambda but I'm still unsure how to use it within the block context.