Eclique
Eclique

Reputation: 25

Ruby function definition

How do I define a function in Ruby so that such call f[true,1,2,3] could be made? I tried something like this
def f(arr) ... end
But it requires f([true,1,2,3]).
I'm total newb in Ruby, just need it to complete certain task.

Upvotes: 0

Views: 136

Answers (1)

Saturn
Saturn

Reputation: 18149

I'd do it like this:

class MyClass
    def [](a,b,c,d)
        print "#{a} #{b} #{c} #{d}"
    end
end

f = MyClass.new

f[true,1,2,3]   # => true 1 2 3

Upvotes: 2

Related Questions