Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: method finder gem example

Tags:

ruby

I found this great gem 'method finder' that I'm trying to use to help improve my understanding of Ruby, problem is that I don't really get it. It gives this example from the docs. The method 'unknown' is supposed to replace whatever method will give the result in the surrounding code, but what is this example telling us?

>> 10.find_method { |n| n.unknown(3) == 1 }
=> ["Fixnum#%", "Fixnum#<=>", "Fixnum#>>", "Fixnum#[]", "Integer#gcd", "Fixnum#modulo", "Numeric#remainder"]
like image 757
BrainLikeADullPencil Avatar asked Sep 14 '26 13:09

BrainLikeADullPencil


1 Answers

It's telling you exactly what you asked it for: all the methods on 10 that return 1 when passed 3:

>> 10 % 3
 => 1 
>> 10 <=> 3
 => 1 
>> 10 >> 3
 => 1 
>> 10[3]
 => 1 
>> …
like image 166
Gareth Avatar answered Sep 16 '26 05:09

Gareth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!