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,
Since Ruby 2.0 there is support of named or keyword parameters.
You may use:
class Fruit
attr_reader :color, :type
def initialize(color: 'green', type: 'pear')
@color = color
@type = type
end
def to_s
"#{color} #{type}"
end
end
puts(Fruit.new) # prints: green pear
puts(Fruit.new(:color => 'red', :type => 'grape')) # prints: red grape
puts(Fruit.new(:type => 'pomegranate')) # prints: green pomegranate
Some interesting notes on this topic: