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...

···

--
Posted via http://www.ruby-forum.com/.

try m.fptr.name

···

On 10-10-15 09:34 PM, John Smith wrote:

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...

--
Kind Regards,
Rajinder Yadav

$ irb

RUBY_VERSION

=> "1.8.6"

···

--
Posted via http://www.ruby-forum.com/\.

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.

···

--
Posted via http://www.ruby-forum.com/.

Thank you for your help

Ted.

···

--
Posted via http://www.ruby-forum.com/.

no such method :\

Ted.

Rajinder Yadav wrote in post #954718:

···

On 10-10-15 09:34 PM, John Smith wrote:

if m.fptr == :gam
  ....
elsif m.fptr == :lin
  ...

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

Ted...

try m.fptr.name

--
Posted via http://www.ruby-forum.com/\.

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 Sat, Oct 16, 2010 at 1:10 PM, John Smith <edvelez.g@gmail.com> wrote:

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.

--
Posted via http://www.ruby-forum.com/\.

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"

···

On Oct 16, 12:29 pm, John Smith <edvele...@gmail.com> wrote:

$ irb>> RUBY_VERSION

=> "1.8.6"

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 16.10.2010 13:58, John Smith wrote:

no such method :\

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

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 Cheek wrote in post #954841:

···

On Sat, Oct 16, 2010 at 1:10 PM, John Smith <edvelez.g@gmail.com> 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.

--
Posted via http://www.ruby-forum.com/\.

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 rvm_textmate

···

On Sat, Oct 16, 2010 at 9:21 PM, John Smith <edvelez.g@gmail.com> 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.