I would like to have a class and some attributes which you can either set during initialization or use its default value.
class Fruit
attr_accessor :color, :type
def initialize(color, type)
@color=color ||= 'green'
@type=type ||='pear'
end
end
apple=Fruit.new(red, apple)
I like vonconrad's answer but would have a separate
defaults
method. Maybe it's not efficient in terms of lines of code, but it's more intention-revealing and involves less cognitive overhead, and less cognitive overhead means more efficient dev onboarding.