if @booked_days.include?(d)
result is true/false, fine...
but is there any way to know if the object (d) is duplicated in the array ?
something like
if @booked_days.duplicated?(d) (getting true/false)
or
if @booked_days.count?(d) (getting the number of duplicated objects)
joss
@booked_days.inject(0) {|cnt, el| d == el ? cnt.succ : cnt}
@booked_days.select {|el| d == el}.size
HTH
Kind regards
robert
thanks a lot... Robert !
As all newrubies, I'll spend the night to translate it (in order to
ameliorate my rating...)
my interest for Ruby is growing everytime I see how powerful it can be !!
Did you succeed or rather want some comments in the code?
> my interest for Ruby is growing everytime I see how powerful it can
> be !!
:-)
PS: Here's an even more general solution that counts occurrences of *all*
elements in an Enumerable:
counts = enum.inject(Hash.new(0)) {|cnt,e| cnt[e]+=1; cnt}
Kind regards
robert
running fine, but had no time actually to look into the code (soccer
world cup, France-Brasil !)
:-) Congrats! Now there's only old and new Europe left in the cup...
At the moment I consider the French to be favorite but I keep my fingers
crossed for the Germans of course.
Kind regards
robert
Even if the French team is more 'experienced' I still consider Germany
has the favorite beacuse playing home (as the French in 98..) and more
I'd like the Germans get the same feeling we got in 98... they deserve
it ! I consider this cup as beautiful as 98 because of the Germans
people behavior... Germany-France will be my favorite final !!!
as you have a lot of Ruby knowledge , I would like to 'exchange'
dot-commas in a string
s= "123.456,78" -> "123,456.78"
I now I should use a s.gsub with a block, but I don't know actually
how to write it... (I can write 3 gsubs.... but it would be ugly.....)
joss
>> "123.456,78".gsub(/[.,]/) {|m| m == "." ? "," : "."}
=> "123,456.78"
But his is far better:
>> "123.456,78".tr ".,", ",."
=> "123,456.78"
Cheers
robert