ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Any reason why this code should not work - The Ruby Way, p270
by Victor Reyes other posts by this author
May 8 2008 5:09AM messages near this date
Re: TDD with Ruby | Re: Any reason why this code should not work - The Ruby Way, p270
I lifted the following code from The Ruby way and tried to use it.
It does not output anything.
Do anyone knows why?

Thank you

Victor

##############################
# This code adds a count method to the Array class
# This code was lifted from:
#  The Ruby Way
#  Second Edition
#  By: Hal Fulton
#  Page: 270
##############################
class Array
       def count
            k=Hash.new(0)
            self.each{|x| k[x]+1 }
            k
       end
end



    @aa = [

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789],

[123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789]
        ]

    @ga = [
            [0,0,0,0,1,9,0,4,0],
            [0,0,4,8,0,0,6,0,0],
            [7,5,0,0,0,0,0,0,2],
            [0,9,0,1,0,2,0,0,4],
            [0,0,0,0,0,3,0,0,0],
            [5,0,0,4,0,6,0,3,0],
            [8,0,0,0,0,0,0,7,3],
            [0,0,6,0,0,8,4,0,0],
            [0,1,0,2,9,0,0,0,0]
            ]


# Test the count method:

         f = @ga[0].count
         puts "f = #{f}"           # The output here was: f =

         f = @aa.count
         puts "f = #{f}"           # The output here was: f =
Thread:
Victor Reyes
jgabrielygalan
Rolando Abarca
Victor Reyes
Jano Svitok
Victor Reyes
Victor Reyes

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved