fork(1) download
  1. class BookInStock
  2.  
  3. attr_accessor :isbn, :price
  4.  
  5. def initialize isbn, price
  6. @isbn = isbn
  7. @price = Float price
  8. end
  9.  
  10. def to_s
  11. "ISBN: #{@isbn}, price: #{@price}"
  12. end
  13.  
  14. def price= new_peice
  15. @price = new_peice
  16. end
  17.  
  18. def price_in_cents
  19. Integer price*100+0.5
  20. end
  21.  
  22. def price_in_cents=cents
  23. @price = cents / 100.0
  24. end
  25.  
  26. end
  27.  
  28. book = BookInStock.new("isbn1", 33.80)
  29. puts "Price = #{book.price}"
  30. puts "Price in cents = #{book.price_in_cents}"
  31. book.price_in_cents = 1234
  32. puts "Price = #{book.price}"
  33. puts "Price in cents = #{book.price_in_cents}"
Success #stdin #stdout 0.01s 6012KB
stdin
Standard input is empty
stdout
Price = 33.8
Price in cents = 3380
Price = 12.34
Price in cents = 1234