P
Paul Private
dear
with the below mentioned script I would like to produce first all of the
Java courses and then the Ruby ones.
however I can't seem to get it to work
I know I can use the partition method but I'm not able to get it to
work.
can you please help me out here
require "collecties/cursus"
class Cursus_applic
cursussen = [Cursus.new('Ruby - 1','Jan', 18.15, 10),
Cursus.new('Ruby - 2','Piet', 18.15, 8),
Cursus.new('Java - 1','Els', 14, 15),
Cursus.new('Java - 2','Jan', 14, 10),
Cursus.new('Java - 3','Piet', 18.15, 8)
]
puts '5. First all Java courses then followed by the others: '
cursus_java = cursussen.partition {|cursus|cursus_java?(true)}
puts '6. Alle cursussen gesorteerd op cursus naam: '
puts '7. Alle cursussen voorafgegaan met de index: '
end
and the cursus.rb is mentioned here below
class Cursus
attr :naam, false
attr_reader :docent
attr :tijdstip, false
attr_reader :aantal_cursisten
def initialize naam, docent, tijdstip, aantal
@naam = naam
@docent = docent
@tijdstip = tijdstip
@aantal_cursisten = aantal
end
def overdag?
@tijdstip < 18
end
def naam? cursus_naam
start = @naam.slice(0, cursus_naam.length)
start == cursus_naam
end
def to_s
tijdstip = overdag? ? "overdag" : "\'s avonds"
"\tDe cursus \'#{@naam}\' wordt #{tijdstip} gegeven door #{@docent}"
end
end
thanks for your help
with the below mentioned script I would like to produce first all of the
Java courses and then the Ruby ones.
however I can't seem to get it to work
I know I can use the partition method but I'm not able to get it to
work.
can you please help me out here
require "collecties/cursus"
class Cursus_applic
cursussen = [Cursus.new('Ruby - 1','Jan', 18.15, 10),
Cursus.new('Ruby - 2','Piet', 18.15, 8),
Cursus.new('Java - 1','Els', 14, 15),
Cursus.new('Java - 2','Jan', 14, 10),
Cursus.new('Java - 3','Piet', 18.15, 8)
]
puts '5. First all Java courses then followed by the others: '
cursus_java = cursussen.partition {|cursus|cursus_java?(true)}
puts '6. Alle cursussen gesorteerd op cursus naam: '
puts '7. Alle cursussen voorafgegaan met de index: '
end
and the cursus.rb is mentioned here below
class Cursus
attr :naam, false
attr_reader :docent
attr :tijdstip, false
attr_reader :aantal_cursisten
def initialize naam, docent, tijdstip, aantal
@naam = naam
@docent = docent
@tijdstip = tijdstip
@aantal_cursisten = aantal
end
def overdag?
@tijdstip < 18
end
def naam? cursus_naam
start = @naam.slice(0, cursus_naam.length)
start == cursus_naam
end
def to_s
tijdstip = overdag? ? "overdag" : "\'s avonds"
"\tDe cursus \'#{@naam}\' wordt #{tijdstip} gegeven door #{@docent}"
end
end
thanks for your help