Ruby: Passing optional objects to method
- by Sam
Class TShirt
def size(suggested_size)
if suggested_size == nil
size = "please choose a size"
else
size = suggested
end
end
end
tshirt = TShirt.new
tshirt.size("M")
== "M"
tshirt = TShirt.new
size = tshirt.size(nil)
== "please choose a size"
What is a better way to have optional objects in a method? Procs?