Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active December 15, 2015 04:04
Show Gist options
  • Select an option

  • Save YumaInaura/b827640b27ed02208aee to your computer and use it in GitHub Desktop.

Select an option

Save YumaInaura/b827640b27ed02208aee to your computer and use it in GitHub Desktop.
Ruby | attr_accessor + initialize でアクセサ変数に代入できない時 ref: http://qiita.com/Yinaura/items/02c8bd7bd87cfa64ce6c
class Book
attr_accessor :price
def initialize
price = 1080
end
end
book = Book.new
p book.price
# => nil
class Book
attr_accessor :price
def initialize
self.price = 1080
end
end
book = Book.new
p book.price
# => 1080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment