Reputation: 578
Can I / how would I go about calling the ternary operator using the send :name, *args, &blk
syntax construct? I don't have a practical reason to do this, but it came up.
Here you can see my woeful attempts:
i = 7
send "?:", proc { i > 2 }, true, false
# => NoMethodError: undefined method `?:' for main:Object
proc { i > 2 }.send "?:", true, false
# => NoMethodError: undefined method `?:' for #<Proc:0x00000001ef77b0@(irb):3>
proc { i > 2 }.call.send "?:", true, false
# => NoMethodError: undefined method `?:' for true:TrueClass
Upvotes: 0
Views: 46
Reputation: 168111
There is no way to do that. The ternary operator construction, or the ?
part of it, is not a method; as you noticed, it is a syntactic construct. Meanwhile, send
can only handle methods.
Upvotes: 1