Dynamically referencing class constants?

How can I do this?

Socket.constants.each {|i|
    puts Socket::#{i} ##does not work of course
}

···

#################################
Futile attempts:

irb(main):023:0> puts Socket::SEEK_CUR ##works of course, the rest does
not
1
irb(main):029:0> puts Socket.new.SEEK_CUR
ArgumentError: wrong number of arguments (0 for 3)
        from (irb):29:in `initialize'
        from (irb):29:in `new'
        from (irb):29
irb(main):030:0> x = "SEEK_CUR"
=> "SEEK_CUR"
irb(main):031:0> Socket::#{x}
irb(main):032:0*
irb(main):033:0* end
NoMethodError: undefined method `end' for Socket:Class
        from (irb):33
irb(main):034:0> Socket::send("SEEK_CUR")
NoMethodError: undefined method `SEEK_CUR' for Socket:Class
        from (irb):34:in `send'
        from (irb):34

Socket.const_get("SEEK_CUR")

···

On 6/13/07, list. rb <list.rb@gmail.com> wrote:

How can I do this?

Socket.constants.each {|i|
    puts Socket::#{i} ##does not work of course
}

#################################
Futile attempts:

irb(main):023:0> puts Socket::SEEK_CUR ##works of course, the rest does
not
1
irb(main):029:0> puts Socket.new.SEEK_CUR
ArgumentError: wrong number of arguments (0 for 3)
        from (irb):29:in `initialize'
        from (irb):29:in `new'
        from (irb):29
irb(main):030:0> x = "SEEK_CUR"
=> "SEEK_CUR"
irb(main):031:0> Socket::#{x}
irb(main):032:0*
irb(main):033:0* end
NoMethodError: undefined method `end' for Socket:Class
        from (irb):33
irb(main):034:0> Socket::send("SEEK_CUR")
NoMethodError: undefined method `SEEK_CUR' for Socket:Class
        from (irb):34:in `send'
        from (irb):34

--
Chris Carter
concentrationstudios.com
brynmawrcs.com

puts "Socket::#{i}"

···

On Thu, 2007-06-14 at 10:16 +0900, list. rb wrote:

How can I do this?

Socket.constants.each {|i|
    puts Socket::"#{i}" ##does not work of course
}

doh!!! sorry, missed the dereference...

···

On Thu, 2007-06-14 at 10:26 +0900, Reid Thompson wrote:

On Thu, 2007-06-14 at 10:16 +0900, list. rb wrote:
> How can I do this?
>
> Socket.constants.each {|i|
> puts Socket::"#{i}" ##does not work of course
> }

puts "Socket::#{i}"

A++

Thanks alot

···

On 6/13/07, Chris Carter <cdcarter@gmail.com> wrote:

On 6/13/07, list. rb <list.rb@gmail.com> wrote:
> How can I do this?
>
> Socket.constants.each {|i|
> puts Socket::#{i} ##does not work of course
> }
>
> #################################
> Futile attempts:
>
> irb(main):023:0> puts Socket::SEEK_CUR ##works of course, the rest
does
> not
> 1
> irb(main):029:0> puts Socket.new.SEEK_CUR
> ArgumentError: wrong number of arguments (0 for 3)
> from (irb):29:in `initialize'
> from (irb):29:in `new'
> from (irb):29
> irb(main):030:0> x = "SEEK_CUR"
> => "SEEK_CUR"
> irb(main):031:0> Socket::#{x}
> irb(main):032:0*
> irb(main):033:0* end
> NoMethodError: undefined method `end' for Socket:Class
> from (irb):33
> irb(main):034:0> Socket::send("SEEK_CUR")
> NoMethodError: undefined method `SEEK_CUR' for Socket:Class
> from (irb):34:in `send'
> from (irb):34
>

Socket.const_get("SEEK_CUR")

--
Chris Carter
concentrationstudios.com
brynmawrcs.com