Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What convention should I use for instance variables?
- class BookInStock
- attr_reader: isbn
- attr_accessor: price
- def initialize (isbn, price)
- @isbn = isbn
- @price = Float (price)
- end
- def price_in_cents
- Integer (price * 100 + 0.5)
- end
- end
- class BookStock
- def set_price (price)
- @price = price
- end
- def get_price
- @price
- end
- end
- class Person
- attr_reader :name
- def initialize(name)
- @name = name
- end
- def blank?
- !@name
- end
- def to_s
- name
- end
- end
- class Person
- def initialize(first_name, last_name)
- @first_name, @last_name = first_name, last_name
- end
- def name
- "#{@first_name} #{@last_name}"
- end
- def blank?
- !@first_name and !@last_name
- end
- def to_s
- name
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment