gem and uninitialized constant

Discussion in 'Ruby' started by John Franey, Apr 6, 2007.

  1. John Franey

    John Franey Guest

    I want to use NetAddr 1.2 with gems 0.9.2 and ruby 1.8.5 on Suse 10.2.
    The lines of code:

    require 'rubygems'
    gem 'netaddr'
    ipadd = NetAddr::CIDR.create("192.9.200.0/24")

    The error: uninitialized constant NetAddr (NameError)


    This works:

    require 'rubygems'
    require_gem 'netaddr'
    ipadd = NetAddr::CIDR.create("192.9.200.0/24")

    But I get the warning: "require_gem is obsolete. Use gem instead."

    Any comments?

    Thanks
     
    John Franey, Apr 6, 2007
    #1
    1. Advertising

  2. On Fri, Apr 06, 2007 at 10:44:00AM +0900, John Franey wrote:
    > I want to use NetAddr 1.2 with gems 0.9.2 and ruby 1.8.5 on Suse 10.2.
    > The lines of code:
    >
    > require 'rubygems'
    > gem 'netaddr'
    > ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >
    > The error: uninitialized constant NetAddr (NameError)
    >
    >
    > This works:
    >
    > require 'rubygems'
    > require_gem 'netaddr'
    > ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >
    > But I get the warning: "require_gem is obsolete. Use gem instead."


    Have you tried:

    require 'rubygems'
    require 'netaddr'

    ?
    (Newer versions of rubygems replace 'require' directly)
     
    Brian Candler, Apr 6, 2007
    #2
    1. Advertising

  3. Brian,

    Thanks for responding:

    This code:

    require 'rubygems'
    require 'netaddr'
    ipadd = NetAddr::CIDR.create("192.9.200.0/24")

    gives:

    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    `gem_original_require': no such file to load -- netaddr (LoadError)
    from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    `require'
    from ci.rb:2

    This code:

    require 'rubygems'
    require 'net_addr'
    ipadd = NetAddr::CIDR.create("192.9.200.0/24")

    works.

    Now, how am I supposed to learn the right string to put into the require
    call. The command to install was:

    gem install netaddr


    I don't remember why I guessed 'net_addr'


    John


    Brian Candler wrote:
    >
    > On Fri, Apr 06, 2007 at 10:44:00AM +0900, John Franey wrote:
    >> I want to use NetAddr 1.2 with gems 0.9.2 and ruby 1.8.5 on Suse 10.2.
    >> The lines of code:
    >>
    >> require 'rubygems'
    >> gem 'netaddr'
    >> ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >>
    >> The error: uninitialized constant NetAddr (NameError)
    >>
    >>
    >> This works:
    >>
    >> require 'rubygems'
    >> require_gem 'netaddr'
    >> ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >>
    >> But I get the warning: "require_gem is obsolete. Use gem instead."

    >
    > Have you tried:
    >
    > require 'rubygems'
    > require 'netaddr'
    >
    > ?
    > (Newer versions of rubygems replace 'require' directly)
    >
    >
    >


    --
    View this message in context: http://www.nabble.com/gem-and-uninitialized-constant-tf3534899.html#a9875785
    Sent from the ruby-talk mailing list archive at Nabble.com.
     
    John J. Franey, Apr 6, 2007
    #3
  4. John J. Franey wrote:
    > Brian,
    >
    > Thanks for responding:
    >
    > This code:
    >
    > require 'rubygems'
    > require 'netaddr'
    > ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >
    > gives:
    >
    > /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    > `gem_original_require': no such file to load -- netaddr (LoadError)
    > from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    > `require'
    > from ci.rb:2
    >
    > This code:
    >
    > require 'rubygems'
    > require 'net_addr'
    > ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >
    > works.
    >
    > Now, how am I supposed to learn the right string to put into the require
    > call. The command to install was:
    >
    > gem install netaddr


    If the gem generates documentation, I'd look there. Otherwise, look into
    your /usr/lib/ruby/gems/1.8/name_of_gem directories for a README or code
    code examples. In case you didn't know it gem_server launches a small
    server, which makes the RDoc documentation accessible (in case the
    developer was smart enough to include such a thing ;)

    Otherwise, you might take your chances and even look at the gem's
    homepage. in this case, it probably is http://netaddr.rubyforge.org


    P.S.:
    A: Because it makes reading replies difficult.
    Q: Why is top-posting bad?


    --
    Phillip "CynicalRyan" Gawlowski
    http://cynicalryan.110mb.com/

    Rule of Open-Source Programming #1:

    Don't whine unless you are going to implement it yourself.
     
    Phillip Gawlowski, Apr 6, 2007
    #4
  5. John Franey

    bbiker Guest

    On Apr 6, 2:50 pm, Phillip Gawlowski <>
    wrote:
    > John J. Franey wrote:
    > > Brian,

    >
    > > Thanks for responding:

    >
    > > This code:

    >
    > > require 'rubygems'
    > > require 'netaddr'
    > > ipadd = NetAddr::CIDR.create("192.9.200.0/24")

    >
    > > gives:

    >
    > > /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    > > `gem_original_require': no such file to load -- netaddr (LoadError)
    > > from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    > > `require'
    > > from ci.rb:2

    >
    > > This code:

    >
    > > require 'rubygems'
    > > require 'net_addr'
    > > ipadd = NetAddr::CIDR.create("192.9.200.0/24")

    >
    > > works.

    >
    > > Now, how am I supposed to learn the right string to put into the require
    > > call. The command to install was:

    >
    > > gem install netaddr

    >
    > If the gem generates documentation, I'd look there. Otherwise, look into
    > your /usr/lib/ruby/gems/1.8/name_of_gem directories for a README or code
    > code examples. In case you didn't know it gem_server launches a small
    > server, which makes the RDoc documentation accessible (in case the
    > developer was smart enough to include such a thing ;)
    >
    > Otherwise, you might take your chances and even look at the gem's
    > homepage. in this case, it probably ishttp://netaddr.rubyforge.org
    >
    > P.S.:
    > A: Because it makes reading replies difficult.
    > Q: Why is top-posting bad?
    >
    > --
    > Phillip "CynicalRyan" Gawlowskihttp://cynicalryan.110mb.com/
    >
    > Rule of Open-Source Programming #1:
    >
    > Don't whine unless you are going to implement it yourself.- Hide quoted text -
    >
    > - Show quoted text -


    I got caught in the same puzzle that the OP got trapped.

    A gem has a name "gemname" which is used to install --- gem install
    gemname
    A "require" loads the gem and needs to know the gem's base
    filename .. which is the filename without an extension.
    Usually (probably 99% of time), the gemname and the base filename are
    the same although it is not a requirement.
    A gem filename may have "rb" as an extension but it could also have
    "so" as an extension ... 'require' is smart enough to look
    for valid extensions.

    As CynicalRyan stated, you have to dig into the documentation and hope
    to find the information.

    In the case of the netaddr gem, the example in the documentation is
    outdated. Only by looking at the list of netaddr's files would you
    have seen "net_addr.rb"
     
    bbiker, Apr 7, 2007
    #5
  6. On Sat, Apr 07, 2007 at 02:49:54AM +0900, John J. Franey wrote:
    > This code:
    >
    > require 'rubygems'
    > require 'net_addr'
    > ipadd = NetAddr::CIDR.create("192.9.200.0/24")
    >
    > works.
    >
    > Now, how am I supposed to learn the right string to put into the require
    > call.


    I'd just do
    ls -lR /usr/lib/ruby/gems/1.8/gems/netaddr*
     
    Brian Candler, Apr 7, 2007
    #6
  7. bbiker wrote:
    >
    > On Apr 6, 2:50 pm, Phillip Gawlowski <>
    > wrote:
    >> John J. Franey wrote:

    >
    >> > This code:

    >>
    >> > require 'rubygems'
    >> > require 'netaddr'

    >
    > fails:
    >> > `gem_original_require': no such file to load -- netaddr (LoadError)
    >> > from

    >> /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require'

    >
    >> > This code:

    >>
    >> > require 'rubygems'
    >> > require 'net_addr'

    > doesn't
    >
    >>
    >> > Now, how am I supposed to learn the right string to put into the

    >> require
    >> > call. The command to install was:

    >>
    >> > gem install netaddr

    >>
    >> If the gem generates documentation, I'd look there. Otherwise, look into
    >> your /usr/lib/ruby/gems/1.8/name_of_gem directories for a README or code
    >> code examples. In case you didn't know it gem_server launches a small
    >> server, which makes the RDoc documentation accessible (in case the
    >> developer was smart enough to include such a thing ;)
    >>
    >> Otherwise, you might take your chances and even look at the gem's
    >> homepage. in this case, it probably ishttp://netaddr.rubyforge.org
    >>
    >>
    >> --
    >> Phillip "CynicalRyan" Gawlowskihttp://cynicalryan.110mb.com/
    >>

    >
    >
    > I got caught in the same puzzle that the OP got trapped.
    >
    > A gem has a name "gemname" which is used to install --- gem install
    > gemname
    > A "require" loads the gem and needs to know the gem's base
    > filename .. which is the filename without an extension.
    > Usually (probably 99% of time), the gemname and the base filename are
    > the same although it is not a requirement.
    > A gem filename may have "rb" as an extension but it could also have
    > "so" as an extension ... 'require' is smart enough to look
    > for valid extensions.
    >
    > As CynicalRyan stated, you have to dig into the documentation and hope
    > to find the information.
    >
    > In the case of the netaddr gem, the example in the documentation is
    > outdated. Only by looking at the list of netaddr's files would you
    > have seen "net_addr.rb"
    >
    >
    >
    >
    >



    I got good responses to this question thanks. Basically, the answer is
    "dig". I can do and did in this case. Digging won't be the best way after
    someone has already solved the problem with a command, which is what I was
    fishing for. Thanks for you help and understanding.

    John

    --
    View this message in context: http://www.nabble.com/gem-and-uninitialized-constant-tf3534899.html#a9885106
    Sent from the ruby-talk mailing list archive at Nabble.com.
     
    John J. Franey, Apr 7, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=

    Uninitialized constant objects

    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=, Jun 1, 2005, in forum: C++
    Replies:
    5
    Views:
    432
    Karl Heinz Buchegger
    Jun 1, 2005
  2. Todd Gardner
    Replies:
    3
    Views:
    542
    Kaspar Schiess
    Jun 17, 2004
  3. Austin 7873
    Replies:
    5
    Views:
    200
    Eric Hodel
    Jan 27, 2007
  4. Dave Tilley
    Replies:
    3
    Views:
    111
    Dave Tilley
    Jan 6, 2008
  5. Charles Hoffman
    Replies:
    0
    Views:
    169
    Charles Hoffman
    Feb 7, 2008
Loading...

Share This Page