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,
More simple way:
class Fruit
attr_accessor :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('red','apple') # prints: red apple
puts Fruit.new(nil,'pomegranate') # prints: green pomegranate