Check contents of a pointer

Hi everyone,

I created a function pointer that points
to a method.

m.fptr = m.method( :sigm )

However… later on I need to do an operation depending on the symbol it
is pointing at:

if m.fptr == :gam

elsif m.fptr == :lin

How do I obtain this symbol value from m.fptr?

Ted…

On 10-10-15 09:34 PM, John S. wrote:

if m.fptr == :gam

elsif m.fptr == :lin

How do I obtain this symbol value from m.fptr?

Ted…

try m.fptr.name

no such method :\

Ted.

Rajinder Y. wrote in post #954718:

On 10-10-15 09:34 PM, John S. wrote:

if m.fptr == :gam

elsif m.fptr == :lin

How do I obtain this symbol value from m.fptr?

Ted…

try m.fptr.name

$ irb

RUBY_VERSION
=> “1.8.6”

On 16.10.2010 13:58, John S. wrote:

no such method :\

What version of Ruby are you using?

irb(main):001:0> RUBY_VERSION
=> “1.8.7”
irb(main):002:0> “”.method(:length).name
=> “length”

irb(main):001:0> RUBY_VERSION
=> “1.9.1”
irb(main):002:0> “”.method(:length).name
=> :length

Cheers

robert

On Sat, Oct 16, 2010 at 1:10 PM, John S. [email protected] wrote:

In all honesty, use rvm (http://rvm.beginrescueend.com/).

It takes a little getting used to if you aren’t that familiar with Unix,
but
after you figure out how it works, it is really nice. You can install
all
the rubies (how I got jruby, macruby, rubinius, MRI 1.8.6, 1.8.7, 1.9.1,
1.9.2) Then it is just “$ rvm use 1.9.1” to switch to that one. Drop
that in
your ~/.profile (or ~/.bash_profile if you’re on Leopard) and it will
always
use that version. Takes a little more work to set it up with your
editor,
but not too bad for TextMate (just set an environment variable in TM,
and
add 1 line to your profile)

Also lets you set up specific versions for specific projects, and even
specific sets of gems for that project, so its gems are segregated from
the
rest of the system. Manages switching rubies and gems for you when you
move
into and out of these project directories.

How should I get 1.9.1,
I’m using MacOS… and tried to find
a more recent version through fink, but
I find none.

Ted.

I don’t understand what you mean by “setting an environment variable in
TextMate” could you explain how you do this… I also happen to use
Textmate for ruby.

Ted.

Josh C. wrote in post #954841:

On Sat, Oct 16, 2010 at 1:10 PM, John S. [email protected] wrote:

In all honesty, use rvm (http://rvm.beginrescueend.com/).

It takes a little getting used to if you aren’t that familiar with Unix,
but
after you figure out how it works, it is really nice. You can install
all
the rubies (how I got jruby, macruby, rubinius, MRI 1.8.6, 1.8.7, 1.9.1,
1.9.2) Then it is just “$ rvm use 1.9.1” to switch to that one. Drop
that in
your ~/.profile (or ~/.bash_profile if you’re on Leopard) and it will
always
use that version. Takes a little more work to set it up with your
editor,
but not too bad for TextMate (just set an environment variable in TM,
and
add 1 line to your profile)

Also lets you set up specific versions for specific projects, and even
specific sets of gems for that project, so its gems are segregated from
the
rest of the system. Manages switching rubies and gems for you when you
move
into and out of these project directories.

On Oct 16, 12:29pm, John S. [email protected] wrote:

$ irb>> RUBY_VERSION

=> “1.8.6”

Then this will work:

ruby-1.8.6-p399 > “”.method(:length).inspect.match(/#([^#]*)>/)[1]
=> “length”

or:

class Method
def name
inspect.match(/#([^#]*)>/)[1]
end
end

ruby-1.8.6-p399 > “”.method(:length).name
=> “length”

Thank you for your help

Yet one… nasty side-effect … it seems at least… is that my
auto-completion in textmate is gone :
I find it so useful… and that is really why TM is my editor for Ruby.

Ted.

On Sat, Oct 16, 2010 at 9:21 PM, John S. [email protected] wrote:

I don’t understand what you mean by “setting an environment variable in
TextMate” could you explain how you do this… I also happen to use
Textmate for ruby.

Ted.

They explain how to do it in the walkthrough
http://rvm.beginrescueend.com/integration/textmate/

Starting where it says “Following that, in Textmate open up the Shell
Variables editor” with this being your goal http://cl.ly/23Yl

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs