Tim Leslie wrote:
On 6/18/06, O Plameras <[EMAIL PROTECTED]> wrote:
Mark Sargent wrote:

 >#!/usr/bin/ruby
 >
 >amount = ARGV[0].to_f
 >
 >remainder = amount % 5
 >base_amount = amount - remainder
 >
 >if (remainder> 2)
 >       x = 5
 >else
 >       x = 0
 >end
 >
 >puts (base_amount + x)

Suggested Ruby coding:

% cat assign.rb

#!/usr/bin/env ruby
class RubyLesson
        def initialize(number)
                @number = number
        end
        def roundNumbers
                remainder = "[EMAIL PROTECTED]".to_i % 5
                base_amount = "[EMAIL PROTECTED]".to_i - remainder
                if ( remainder > 2 )
print "The number ", "[EMAIL PROTECTED]".to_i, " is rounded to ", base_amount + 5, "\n"
                else
print "The number ", "[EMAIL PROTECTED]".to_i, " is rounded to ", base_amount, "\n"
                end
        end
end
s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
s.each {
        |x|
        aRubyLesson = RubyLesson.new(x)
        aRubyLesson.roundNumbers
}


I'm not a ruby programmer, but can I ask why you'd make this part of a
class? Surely a function roundNumbers(x) would work just as well? The
whole class infrastructure seems rather redundant and makes what
should be simple code overly verbose.

It's part of an effort to discipline my programming-mental-attitude to think object-oriented. So, eventually, it becomes natural and conforming with the concept that Ruby is pure
object-oriented.

O Plameras
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to