Novemberain.com co-author
Monday, April 9, 2007 12:36:44 PM
I'll put most interesting thoughts here (translated in English).
speaking few languages about programming, interfaces, culture, maths and nature
Monday, April 9, 2007 12:36:44 PM
Monday, March 26, 2007 6:27:17 PM
Sunday, February 4, 2007 8:02:39 AM
Friday, January 12, 2007 11:27:59 PM
class Customer
attr_reader :name
def initialize(name)
@name = name
@rentals = []
end
def add_rental(arg)
@rentals << arg
end
def statement
total_amount, frequent_renter_points = 0, 0
result = "Rental Record for #{@name}\n"
@rentals.each do |element|
this_amount = 0
# determine amounts for each line
case element.movie.price_code
when Movie::REGULAR
this_amount += 2
this_amount += (element.days_rented - 2) * 1.5 if element.days_rented > 2
when Movie::NEW_RELEASE
this_amount += element.days_rented * 3
when Movie::CHILDRENS
this_amount += 1.5
this_amount += (element.days_rented - 3) * 1.5 if element.days_rented > 3
end
# add frequent renter points
frequent_renter_points += 1
# add bonus for a two day new release rental
frequent_renter_points += 1 if element.movie.price_code == Movie.NEW_RELEASE && element.days_rented > 1
# show figures for this rental
result += "\t" + element.movie.title + "\t" + this_amount.to_s + "\n"
total_amount += this_amount
end
# add footer lines
result += "Amount owed is #{total_amount.to_s}\n"
result += "You earned #{frequent_renter_points.to_s} frequent renter points"
result
end
end
class Rental
...
def determine_amount
this_amount = 0
case movie.price_code
when Movie::REGULAR
this_amount += 2
this_amount += (days_rented - 2) * 1.5 if days_rented > 2
when Movie::NEW_RELEASE
this_amount += days_rented * 3
when Movie::CHILDRENS
this_amount += 1.5
this_amount += (days_rented - 3) * 1.5 if days_rented > 3
end
end
def bonus
if movie.price_code == Movie.NEW_RELEASE && days_rented > 1
1
else
0
end
end
def frequent_renter_points; 1; end
end
class Customer
attr_reader :name
def initialize(name)
@name = name
@rentals = []
end
def add_rental(arg)
@rentals << arg
end
def statement
total_amount, frequent_renter_points = 0, 0
result = "Rental Record for #{@name}\n"
@rentals.each do |element|
this_amount = element.determine_amount
frequent_renter_points += element.frequent_renter_points
frequent_renter_points += element.bonus
# show figures for this rental
result += "\t" + element.movie.title + "\t" + this_amount.to_s + "\n"
total_amount += this_amount
end
# add footer lines
result += "Amount owed is #{total_amount.to_s}\n"
result += "You earned #{frequent_renter_points.to_s} frequent renter points"
result
end
end
Monday, December 4, 2006 6:58:06 PM
Thursday, November 23, 2006 8:32:21 AM
Sunday, October 29, 2006 11:18:44 PM
a b c
a(b(c()))
method_missing(:a, method_missing(:b, method_missing(:c)))
put an apple on the table to the left OR to the right of me
Sunday, October 29, 2006 11:12:09 PM
#step-1-atransforms into
id="step-"). Find
buffer.rb, method
parse_class_and_idand add
0-9to regexp.
Sunday, October 29, 2006 6:14:05 PM
Wednesday, October 25, 2006 9:17:42 PM
anonymous
anonymous
anonymous
anonymous
anonymous
anonymous
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
| ||||||
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |