accessing object contents

Discussion in 'Ruby' started by John Doe, Mar 19, 2011.

  1. John Doe

    John Doe Guest

    given
    => #<Dnsruby::Name: www.nbc.com.>

    what's the proper way of getting to "www.nbc.com."? is it
    with the to_s method?

    obj.to_s

    --
    Posted via http://www.ruby-forum.com/.
     
    John Doe, Mar 19, 2011
    #1
    1. Advertising

  2. [Note: parts of this message were removed to make it a legal post.]

    On Sat, Mar 19, 2011 at 11:22 PM, John Doe <> wrote:

    > given
    > => #<Dnsruby::Name: www.nbc.com.>
    >
    > what's the proper way of getting to "www.nbc.com."? is it
    > with the to_s method?
    >
    > obj.to_s
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >


    Override the to_s method in your class and define it to print out the value
    of variable. Then you can call to_s method on the object.
    --
    Mayank Kohaley
     
    Mayank Kohaley, Mar 19, 2011
    #2
    1. Advertising

  3. John Doe wrote in post #988311:
    > given
    > => #<Dnsruby::Name: www.nbc.com.>


    Is that output from irb? irb uses the "inspect" method to display a
    value.

    > what's the proper way of getting to "www.nbc.com."?


    Depends entirely on the class in question. Look at the documentation for
    Dnsruby::Name, or at the source code, to see what methods are available.

    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Mar 19, 2011
    #3
    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. Don Adams
    Replies:
    1
    Views:
    624
    Martin Honnen
    Mar 5, 2004
  2. paul cannon
    Replies:
    0
    Views:
    301
    paul cannon
    Mar 15, 2005
  3. paul cannon
    Replies:
    0
    Views:
    436
    paul cannon
    Mar 16, 2005
  4. Jeff Epler
    Replies:
    1
    Views:
    352
    Duncan Booth
    Mar 16, 2005
  5. Kamarulnizam Rahim
    Replies:
    4
    Views:
    246
    Robert Klemme
    Jan 28, 2011
Loading...

Share This Page