Reputation: 15156
Let say I have a variable and lambda defined somewhere
phone = "1(234)567-89-01"
lambda = -> { gsub(/[^0-9]/, '') }
How can I apply lambda to the phone to get 12345678901
?
P.S. I know I can go with the following approach:
lambda = -> (arg) { arg.gsub(/[^0-9]/, '') }
lambda.call(phone)
#=> "12345678901"
But I want to be laconic.
Upvotes: 9
Views: 577
Reputation: 52357
You can use BasicObject#instance_exec
:
phone.instance_exec &lambda
#=> "12345678901"
Upvotes: 15