cd0j0
cd0j0

Reputation: 21

Using a "?" when initialising an instance variable

I am trying to have sushiable? return an instance variable set in initialise but I can't seem to get it to work. What am I doing wrong?

attr_accessor :weight, :value, :sushiable?

def initialize (weight,value, sushiable?)
  @weight = weight
  @value = value
  @sushiable = sushiable?
end

# def sushiable?
#   false
# end

Upvotes: 0

Views: 54

Answers (1)

mrodrigues
mrodrigues

Reputation: 1082

Using ? is only valid for methods names, not for variables. So, the correct way would be:

attr_accessor :weight, :value, :sushiable

def initialize (weight, value, sushiable)
  @weight = weight
  @value = value
  @sushiable = sushiable
end

def sushiable?
  sushiable
end

Upvotes: 4

Related Questions