Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ruby passing lots of args
- def my_method(arg1, arg2, ..., arg20)
- #do some stuff
- my_second_method(arg1, arg2, ..., arg20)
- #do other stuff
- end
- def my_method(arg1, arg2, ..., arg20)
- #do some stuff
- my_second_method(args[array])
- #do other stuff
- end
- def one(*args)
- # process/validate args
- two(*args) # Note that the splat is needed here too.
- end
- def two(*args)
- # do work
- end
- def my_method(*args)
- # do some stuff
- my_second_method(*args)
- # do other stuff
- end
- def my_second_method(*args)
- # use args[0] through args[19]
- end
- render :partial => "new", :locals => {:object => @my_object}
- def as_array(*args)
- if args.length == 3
- a, b, c = args
- puts "a=#{a} b=#{b} c=#{c}"
- end
- end
- as_array 1, 2, 3
- def method1(*args)
- method2(*args)
- end
- def method2(*args)
- end
- method1(a, b, c, d, e, f, g)
Add Comment
Please, Sign In to add comment