How do I tell the difference between a class C and the singletonclass of an instance of C

Discussion in 'Ruby' started by deanwampler@gmail.com, Nov 2, 2007.

  1. Guest

    , Nov 2, 2007
    #1
    1. Advertising

  2. Guest

    Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    I just figured out a way, if I also have the instance "c".

    c.instance_of?(C) # => true
    c.instance_of?(sing) # => false

    Also works for kind_of? and is_a?

    Thanks, Dean! ;)

    On 11/2/07, Dean Wampler <> wrote:
    >
    > Suppose that:
    >
    > class C; end
    > c = C.new
    > sing = (class << c; self; end)
    >
    > If a method is called with C and sing, but I don't know which is first and
    > which is second in the parameter list, how do I tell them apart?
    >
    > Thanks,
    > dean
    >
    > --
    > Dean Wampler
    > http://www.objectmentor.com
    > http://www.aspectprogramming.com
    > http://aquarium.rubyforge.org
    > http://www.contract4j.org





    --
    Dean Wampler
    http://www.objectmentor.com
    http://www.aspectprogramming.com
    http://aquarium.rubyforge.org
    http://www.contract4j.org
     
    , Nov 2, 2007
    #2
    1. Advertising

  3. -a-geek.org Guest

    "Dean Wampler" <> writes:

    > Suppose that:
    >
    > class C; end
    > c = C.new
    > sing = (class << c; self; end)
    >
    > If a method is called with C and sing, but I don't know which is first and
    > which is second in the parameter list, how do I tell them apart?


    C.name ==> "C"
    sing.name ==> ""

    YS
     
    -a-geek.org, Nov 2, 2007
    #3
  4. Guest

    Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    Thanks.

    Correction: only instance_of? works. is_a? and kind_a? both return true for
    "C" and "sing".

    On 11/2/07, Yohanes Santoso <-a-geek.org> wrote:
    >
    > "Dean Wampler" <> writes:
    >
    > > Suppose that:
    > >
    > > class C; end
    > > c = C.new
    > > sing = (class << c; self; end)
    > >
    > > If a method is called with C and sing, but I don't know which is first

    > and
    > > which is second in the parameter list, how do I tell them apart?

    >
    > C.name ==> "C"
    > sing.name ==> ""
    >
    > YS
    >
    >



    --
    Dean Wampler
    http://www.objectmentor.com
    http://www.aspectprogramming.com
    http://aquarium.rubyforge.org
    http://www.contract4j.org
     
    , Nov 2, 2007
    #4
    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. jakk
    Replies:
    4
    Views:
    12,231
  2. Replies:
    10
    Views:
    35,902
    jporter892
    Jun 6, 2011
  3. Jan Kokoska
    Replies:
    7
    Views:
    1,266
    John J. Lee
    Dec 6, 2003
  4. John M. Gabriele
    Replies:
    18
    Views:
    1,158
    Steven Bethard
    Feb 18, 2005
  5. walterbyrd
    Replies:
    7
    Views:
    314
    Asun Friere
    May 17, 2007
Loading...

Share This Page