Question: 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)

```

Answer: 
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:

* [Keyword arguments in Ruby 2.0](http://brainspec.com/blog/2012/10/08/keyword-arguments-ruby-2-0/)
* [Ruby 2.0.0 by Example](http://blog.marc-andre.ca/2013/02/23/ruby-2-by-example/)
* [Named parameters in Ruby 2](https://stackoverflow.com/questions/15308163/named-parameters-in-ruby-2)
I'd do it like this:

```
class Fruit
  attr_accessor :color, :type

  def initialize(args={})
    options = {:color => 'green', :type => 'pear'}.merge(args)

    self.color = options[:color]
    self.type  = options[:type]
  end
end

apple = Fruit.new(:color => 'red', :type => 'apple')

```

This way, you never have to worry about missing arguments--or their order--and you'll always have your default values right there. `.merge` will of course overwrite the default values if they're present.