[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

"soemthing".pluralize/at/from/... -> NoMethodError

David Krmpotic

1/14/2007 12:24:00 PM

Hello,


I've been wondering about this for some time now.. Why don't any of the
following methods work: string.at/from/first/last/humanize/pluralize ?
IRB returns:

NoMethodError: undefined method `pluralize' for "something":String

You can try it yourself (also by using web IRB from here:
http://tryruby....)

Those methods are mentioned in "Agile Development with Rails" for
example.. you can also see people using them on Google code search.

However, they are not mentioned in documentation:
http://ruby-doc.org/core/classes/S...

This is funny. Also.. string.to_json and string.to_yaml are mentioned in
the agile book, but don't work either.

This example doesn't go through in IRB:

# For demo purposes, create a Ruby structure with two attributes
Rating = Struct.new(:name, :ratings)
rating = Rating.new("Rails" , [ 10, 10, 9.5, 10 ])
# and serialize an object of that structure two ways...
puts rating.to_json #=> ["Rails", [10, 10, 9.5, 10]]
puts rating.to_yaml #=> --- !ruby/struct:Rating
name: Rails
ratings:
- 10
- 10
- 9.5
- 10

Can you help me understand all this? Thank you!

David

--
Posted via http://www.ruby-....

9 Answers

dblack

1/14/2007 12:26:00 PM

0

Jamis Buck

1/14/2007 3:27:00 PM

0

David,

Those are not standard Ruby methods. They are defined in the Rails
ActiveSupport library, and thus can only be accessed from within Rails
applications (or other applications that explicitly require
ActiveSupport).

- Jamis

David Krmpotic wrote:
> Hello,
>
>
> I've been wondering about this for some time now.. Why don't any of the
> following methods work: string.at/from/first/last/humanize/pluralize ?
> IRB returns:
>
> NoMethodError: undefined method `pluralize' for "something":String
>
> You can try it yourself (also by using web IRB from here:
> http://tryruby....)
>
> Those methods are mentioned in "Agile Development with Rails" for
> example.. you can also see people using them on Google code search.
>
> However, they are not mentioned in documentation:
> http://ruby-doc.org/core/classes/S...
>
> This is funny. Also.. string.to_json and string.to_yaml are mentioned in
> the agile book, but don't work either.
>
> This example doesn't go through in IRB:
>
> # For demo purposes, create a Ruby structure with two attributes
> Rating = Struct.new(:name, :ratings)
> rating = Rating.new("Rails" , [ 10, 10, 9.5, 10 ])
> # and serialize an object of that structure two ways...
> puts rating.to_json #=> ["Rails", [10, 10, 9.5, 10]]
> puts rating.to_yaml #=> --- !ruby/struct:Rating
> name: Rails
> ratings:
> - 10
> - 10
> - 9.5
> - 10
>
> Can you help me understand all this? Thank you!
>
> David


--
Posted via http://www.ruby-....

David Krmpotic

1/14/2007 6:55:00 PM

0

Ok, that explains everything - thank you very much Jamis, I appreciate
it!



Jamis Buck wrote:
> David,
>
> Those are not standard Ruby methods. They are defined in the Rails
> ActiveSupport library, and thus can only be accessed from within Rails
> applications (or other applications that explicitly require
> ActiveSupport).
>
> - Jamis

--
Posted via http://www.ruby-....

Carlos López

1/15/2007 5:25:00 PM

0

I think you must require 'rubygems' after 'active_support'.

On 1/15/07, Nathan Smith <nlloyds@gmail.com> wrote:
> On 1/14/07, Jamis Buck <jamis@37signals.com> wrote:
> >
> > David,
> >
> > Those are not standard Ruby methods. They are defined in the Rails
> > ActiveSupport library, and thus can only be accessed from within Rails
> > applications (or other applications that explicitly require
> > ActiveSupport).
> >
> > - Jamis
> >
> >
> >
> >
> You can still use ActiveSupport without Rails. Just
>
> gem install ActiveSupport
>
> and then require 'active_support' in your program and pluralize away!
>
> Nate
>
>

Carlos López

1/15/2007 5:26:00 PM

0

I wanted say:
"you must require 'rubygems' before 'active_support'" (s/after/before)
:-p

David Krmpotic

1/15/2007 6:34:00 PM

0

Hmm, when in IRB, I enter:

irb(main)> require 'rubygems'
=> true
irb(main)> require_gem 'activesupport'
=> true

but I still get NoMethodError when doing "something".pluralize .. now
sure, I think it worked 2 days ago...

What am I missing?
thank you

--
Posted via http://www.ruby-....

David Krmpotic

1/15/2007 7:51:00 PM

0

ah now I know why.. this works:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'active_support'
=> true

interesting.. can someone explain what is happening?
so require_gem is no good in irb .. why it doesn't report an error?


thank you



David Krmpotic wrote:
> Hmm, when in IRB, I enter:
>
> irb(main)> require 'rubygems'
> => true
> irb(main)> require_gem 'activesupport'
> => true
>
> but I still get NoMethodError when doing "something".pluralize .. now
> sure, I think it worked 2 days ago...
>
> What am I missing?
> thank you


--
Posted via http://www.ruby-....

Austin Ziegler

1/15/2007 10:45:00 PM

0

On 1/15/07, David Krmpotic <david.krmpotic@gmail.com> wrote:
> ah now I know why.. this works:
>
> irb(main):001:0> require 'rubygems'
> => true
> irb(main):002:0> require 'active_support'
> => true
>
> interesting.. can someone explain what is happening?
> so require_gem is no good in irb .. why it doesn't report an error?

Yes. require_gem is deprecated. Don't use it if at all possible.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Bob Showalter

1/16/2007 5:24:00 PM

0

On 1/15/07, David Krmpotic <david.krmpotic@gmail.com> wrote:
> ah now I know why.. this works:
>
> irb(main):001:0> require 'rubygems'
> => true
> irb(main):002:0> require 'active_support'
> => true
>
> interesting.. can someone explain what is happening?
> so require_gem is no good in irb .. why it doesn't report an error?

require_gem is "good"; it just isn't doing what you think it does.

Here's a good discussion of the issue:
http://redhanded.hobix.com/inspect/autorequireIsBasicallyGoneEve...