0
votes

My Code

def property_values_list
  property_values = {"ceremonial"=>249, "party"=>250, "wedding"=>251, "casual"=>252} 
end

$property_values = property_values_list()

class Design
  attr_reader  :occasion_ids

  def occasion_ids=(property_name)
    self.occasion_ids = []
    self.occasion_ids << $property_values[property_name]
  end
end

d = Design.new
d.occasion_ids = 'party'

Error

SystemStackError: stack level too deep from .rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/irb/workspace.rb:80 Maybe IRB bug!

1
Remove recursion from occasio_ids= method and try to avoid using global variables. - taro

1 Answers

1
votes

That is not a bug, it is just a infinite recursion, because you do a call to assign method occasion_ids= from the method itself:

def occasion_ids=(property_name)
   self.occasion_ids = []

Do assigning to an instance variable:

def occasion_ids=(property_name)
   @occasion_ids = []