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: 
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.
Ruby version: 3.1

I faced the same issue while trying to initialize my classes with some default values.

The best approach for me was to use "named argument". Check out this [link](https://www.ombulabs.com/blog/ruby/learning/methods-arguments-ruby-part2.html) for a better understanding.

```
class Fruit
  attr_accessor :color, :type
  def initialize(color: 'green', type: 'pear')
    @color = color
    @type = type
  end
end

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

```