f = lambda {|..." />

Ruby: Can lambda function parameters have default values?

In Ruby 1.9+, you can use either of the old-style lambdas or the new "arrow" lambda syntax to set a default parameter: ruby-1.9.1-p378 > f = lambda {|x, y=1| puts(x+y) } => # ruby-1.9.1-p378 > f. Call(1) 2 => nil ruby-1.9.1-p378 > f. Call(1,5) 6 => nil ruby-1.9.1-p378 > f = ->(a, b=5) { puts(a+b) } => # ruby-1.9.1-p378 > f.

Call(1) 6 => nil ruby-1.9.1-p378 > f. Call(1,2) 3 => nil.

In Ruby 1.8. X you can sort of fake it along the lines of: def creator lambda do |*args| raise ArgumentError if args. Empty? Or args.

Size > 2 arg1, arg2 = args puts arg1 puts arg2 unless arg2. Nil? End end >> test = creator => # >> test.

Call("foo") foo => nil >> test. Call("foo", "bar") foo bar => nil >> test. Call("foo", "bar", "baz") ArgumentError: ArgumentError Edit: The above example defaults the second argument to nil, but if you wish to have another default you can assign arg2 based on args.

Size (e.g. Arg2 = mydefault if args.Size.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions