Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > quick question

Reply
Thread Tools

quick question

 
 
Johnathan Smith
Guest
Posts: n/a
 
      01-17-2008
hey

how do i access i global variable in ruby?

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

 
Reply With Quote
 
 
 
 
Ilan Berci
Guest
Posts: n/a
 
      01-17-2008
Johnathan Smith wrote:
> hey
>
> how do i access i global variable in ruby?
>
> thanks


Trick question! There are no globals in ruby! What do I win?

ilan


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

 
Reply With Quote
 
 
 
 
Justin Collins
Guest
Posts: n/a
 
      01-17-2008
Ilan Berci wrote:
> Johnathan Smith wrote:
>
>> hey
>>
>> how do i access i global variable in ruby?
>>
>> thanks
>>

>
> Trick question! There are no globals in ruby! What do I win?
>
> ilan
>


Sorry...

Global variables begin with $

irb(main):001:0> def a_method
irb(main):002:1> puts $global_var
irb(main):003:1> end
=> nil
irb(main):004:0> a_method
nil
=> nil
irb(main):005:0> $global_var = "Hi, there. I'm a global"
=> "Hi, there. I'm a global"
irb(main):006:0> a_method
Hi, there. I'm a global
=> nil

-Justin


 
Reply With Quote
 
Johnathan Smith
Guest
Posts: n/a
 
      01-17-2008
cheers guys
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ilan Berci
Guest
Posts: n/a
 
      01-17-2008
Justin Collins wrote:
> Ilan Berci wrote:
>>
>> ilan
>>

>
> Sorry...
>
> Global variables begin with $
>
> irb(main):001:0> def a_method
> irb(main):002:1> puts $global_var
> irb(main):003:1> end
> => nil
> irb(main):004:0> a_method
> nil
> => nil
> irb(main):005:0> $global_var = "Hi, there. I'm a global"
> => "Hi, there. I'm a global"
> irb(main):006:0> a_method
> Hi, there. I'm a global
> => nil
>
> -Justin


Sorry.. I had a brain fart.. was thinking of methods.. should have read
more carefully..

irb(main):001:0> $global_var = "global!"
=> "global!"
irb(main):002:0> global_variables.grep /global_var/
=> ["$global_var"]
irb(main):003:0>
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick question, hopefully quick answer. ~misfit~ NZ Computing 114 01-06-2005 01:36 PM
Quick Question Quick Answer JKop C++ 11 05-24-2004 09:46 PM
Quick Restore for a Compaq not so quick! Croos Bustamunky Computer Support 2 05-15-2004 04:17 AM
PanasonicBQ390 "quick" charger - How quick? Ol' Bab Digital Photography 1 01-17-2004 06:54 AM



Advertisments