On Wed, Feb 24, 2016 at 10:51 AM, A Berger <aberger7890 / gmail.com> wrote:
> can i "automagically" select a method by type or count of args?

no. ruby favors dynamic typing wc allows any type and any number of arguments.
if you want something close or near to what you want, try the contract gem.
warning: untested by experience : )

eg,
>> require 'contracts'
=> true
>>
>> class Factorial
 |   include Contracts
 |
 |   Contract 1 => 1
 |   def fact(x)
 |     x
 |   end
 |
 |   Contract Num => Num
 |   def fact(x)
 |     x * fact(x - 1)
 |   end
 |
 |   Contract String => String
 |   def fact(x)
 |     "whatever #{x} :P"
 |   end
 |
 | end
=> :fact

>> f=Factorial.new
=> #<Factorial:0x005578ffa25210>
>> f.fact(5)
=> 120
>> f.fact(1)
=> 1
>> f.fact("hello")
=> "whatever hello :P"

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>