[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File scope variable

Martin Martinos

10/3/2007 3:33:00 AM

I tried to find a way to have a variable that has a file scope. A
variable that I can access in each function of each class but which is
private to my .rb file.

Does anybody has a idea?
--
Posted via http://www.ruby-....

13 Answers

7stud 7stud

10/3/2007 3:37:00 AM

0

Martin Martinos wrote:
> A
> variable that I can access in each function of each class but which is
> private to my .rb file.
>
> Does anybody has a idea?

Yes. Don't do it. That's a horrible idea. If a method in your class
needs a value, pass the value as an argument.

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

Martin Martinos

10/3/2007 4:22:00 AM

0

7stud -- wrote:
> Martin Martinos wrote:
>> A
>> variable that I can access in each function of each class but which is
>> private to my .rb file.
>>
>> Does anybody has a idea?
>
> Yes. Don't do it. That's a horrible idea. If a method in your class
> needs a value, pass the value as an argument.


I agree with you on this point, but in some circumstance it would be
interesting to have file scoped variables. There are at least one
built-in variable that is local to the current file and it's the
__FILE__ variable. In fact in my require function I would use a local
variable that tells me what is the current file folder path. I would
also use it to localize the path of the binary files that my script
uses. I don't think in that case its a bad idea since __FILE__ has also
a file scope.

example:

require 'pathname'
my_path = Pathname.new(__FILE__).realpath.dirname

require my_path +'mylib'

def exec_my_bin()
`#{my_path + 'bin/mybin'}`
end
--
Posted via http://www.ruby-....

Rick DeNatale

10/3/2007 12:00:00 PM

0

On 10/3/07, Martin Martinos <chabotm@yahoo.com> wrote:
> There are at least one
> built-in variable that is local to the current file and it's the
> __FILE__ variable. In fact in my require function I would use a local
> variable that tells me what is the current file folder path. I would
> also use it to localize the path of the binary files that my script
> uses. I don't think in that case its a bad idea since __FILE__ has also
> a file scope.

Well, it's not that __FILE__ has a file scope, it's that it is a
pseudovariable which is magically set to the current file name.

If you really need to do this, maybe a hash keyed by __FILE__ sort of
like a file-local as an analogy to a thread local variable.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Robert Klemme

10/4/2007 1:52:00 PM

0

2007/10/3, Martin Martinos <chabotm@yahoo.com>:
> 7stud -- wrote:
> > Martin Martinos wrote:
> >> A
> >> variable that I can access in each function of each class but which is
> >> private to my .rb file.
> >>
> >> Does anybody has a idea?
> >
> > Yes. Don't do it. That's a horrible idea. If a method in your class
> > needs a value, pass the value as an argument.
>
>
> I agree with you on this point, but in some circumstance it would be
> interesting to have file scoped variables. There are at least one
> built-in variable that is local to the current file and it's the
> __FILE__ variable. In fact in my require function I would use a local
> variable that tells me what is the current file folder path. I would
> also use it to localize the path of the binary files that my script
> uses. I don't think in that case its a bad idea since __FILE__ has also
> a file scope.
>
> example:
>
> require 'pathname'
> my_path = Pathname.new(__FILE__).realpath.dirname
>
> require my_path +'mylib'
>
> def exec_my_bin()
> `#{my_path + 'bin/mybin'}`
> end

What is wrong with this solution? my_path *is* visible in the current
file only as far as I can see. Btw, what are you trying to achieve?

Kind regards

robert

Martin Martinos

10/4/2007 2:15:00 PM

0

Robert Klemme wrote:
> 2007/10/3, Martin Martinos <chabotm@yahoo.com>:
>>
>> example:
>>
>> require 'pathname'
>> my_path = Pathname.new(__FILE__).realpath.dirname
>>
>> require my_path +'mylib'
>>
>> def exec_my_bin()
>> `#{my_path + 'bin/mybin'}`
>> end
>
> What is wrong with this solution? my_path *is* visible in the current
> file only as far as I can see. Btw, what are you trying to achieve?
>
> Kind regards
>
> robert

In fact, it only visible in the current file but it's not visible in the
exec_my_bin() function and I don't want to write:

def exec_my_bin()
`#{Pathname.new(__FILE__).realpath.dirname + 'bin/mybin'}`
end

Also I don't want to use a global variable, which I think is a bad idea
since I don't want to use it in another file.

Thanks
--
Posted via http://www.ruby-....

Robert Klemme

10/4/2007 2:20:00 PM

0

2007/10/4, Martin Martinos <mchabotsol@hotmail.com>:
> Robert Klemme wrote:
> > 2007/10/3, Martin Martinos <chabotm@yahoo.com>:
> >>
> >> example:
> >>
> >> require 'pathname'
> >> my_path = Pathname.new(__FILE__).realpath.dirname
> >>
> >> require my_path +'mylib'
> >>
> >> def exec_my_bin()
> >> `#{my_path + 'bin/mybin'}`
> >> end
> >
> > What is wrong with this solution? my_path *is* visible in the current
> > file only as far as I can see. Btw, what are you trying to achieve?
> >
> > Kind regards
> >
> > robert
>
> In fact, it only visible in the current file but it's not visible in the
> exec_my_bin() function and I don't want to write:

Right you are. I overlooked that one. You could work around that
using a lambda:

$ ruby <<XXX
> foo = 100
> bar = lambda { puts foo }
> bar[]
> XXX
100

> def exec_my_bin()
> `#{Pathname.new(__FILE__).realpath.dirname + 'bin/mybin'}`
> end
>
> Also I don't want to use a global variable, which I think is a bad idea
> since I don't want to use it in another file.

Reasonable. But still, what do you need that for?

Kind regards

robert

JRStern

5/11/2013 6:25:00 PM

0

On Sat, 11 May 2013 11:12:38 -0700, JRStern <JRStern@foobar.invalid>
wrote:

>On Sat, 11 May 2013 09:23:59 -0700, "Ian J. Ball"
><ijball-NO_SPAM@mac.invalid> wrote:
>
>>Vegas - A mostly satisfying conclusion to this series (but how they left
>>Jack Lamb and Mia kind of sucked... :( ). Anyway, I'm of the opinion
>>that CBS made a mistake not renewing this.
>
>Seriously, the best plan they had to kill Gainsley was to go
>themselves and hide behind the hay bales? Episode was like a two year
>story arc used up in one night.
>
>>Blue Bloods - Kamar de los Reyes (Antonio "The Hole" Vega, from OLTL)
>>was back as the villainous head of an evil street gang (at least *this*
>>show knows how to use de los Reyes correctly!!), as the season wraps up
>>with our heros taking down the villainous gang, after Diggle... er, I
>>mean, *The Mayor*, gets shot when the gang tricks a retarded patsy in to
>>shooting at Tom Selleck.
>> What is going on with Jamie this season?! They've suddenly turned the
>>character hostile, and I can't figure out why...
>> P.S. So, let's take bets? - Will Marisa Ramirez be back next season
>>as Danny's partner: yes or no?
>
>A two-episode arc the whole point of which was to motivate the big
>crackdown at the end. Carrie-Anne Moss spends the last episode
>unconscious, line up the Emmy nominations.
>
>J.

Oh yeah, and "Undercover Boss, Epic Employees"

In theory this was a go-back to see how the employees shown on
previous episodes did with their big gifts and new promotions. In
fact it looks like it was filmed no more than a month later, and none
of the parts that I saw showed anything new - except that the fat
*boss* from one episode managed to lose 100 pounds, so I guess some
time must have passed there. But they did get one thing right,
several times I heard, "I got this $20,000 for appearing on Undercover
Boss", which was unfortunately true, even though the show makes out
that the gifts are FROM the boss for previously undiscovered merit.

The show often rubs me the wrong way, showing struggling people in
underpaid jobs, clueless bosses, dysfunctional organizations.

This upcoming Fox show, what's the title, "Toxic Office: Does Someone
Have to Go?", now that is going to be something. Will everyone there
get $20,000 for appearing?

J.

Thanatos

5/11/2013 9:50:00 PM

0

In article <9h2to8tolv28vq5vkvcqe6hhg0pdmn387s@4ax.com>,
JRStern <JRStern@foobar.invalid> wrote:

> Oh yeah, and "Undercover Boss, Epic Employees"
>
> In theory this was a go-back to see how the employees shown on
> previous episodes did with their big gifts and new promotions. In
> fact it looks like it was filmed no more than a month later, and none
> of the parts that I saw showed anything new - except that the fat
> *boss* from one episode managed to lose 100 pounds, so I guess some
> time must have passed there. But they did get one thing right,
> several times I heard, "I got this $20,000 for appearing on Undercover
> Boss", which was unfortunately true, even though the show makes out
> that the gifts are FROM the boss for previously undiscovered merit.
>
> The show often rubs me the wrong way, showing struggling people in
> underpaid jobs, clueless bosses, dysfunctional organizations.

It also seems like it would engender a lot of bad morale among the rest
of the employees. "So Jane gets teamed up to work with the boss the day
he comes in and comes out of it with 20 grand and I still have to sweep
floors for minimum wage?"

Anim8rFSK

5/12/2013 2:15:00 AM

0

In article
<ijball-NO_SPAM-D3F6AE.09235911052013@news.eternal-september.org>,
"Ian J. Ball" <ijball-NO_SPAM@mac.invalid> wrote:

> In article <kmli2a$kj3$1@dont-email.me>, "Obveeus" <Obveeus@aol.com>
> wrote:
>
> > What did you watch?
>
> On a day I wanted to run errands, but was out of gas (physically), I
> watched:
>
>
> The Big Bang Theory (recorded) - "The Love Spell Potential". Decent
> episode in which Penny, Amy and Bernadette join Sheldon and Leonard's,
> with Wolowitz as Dungeon Master!! D&D game - Simon Helberg is
> surprisingly deft at impressions!

Good stuff until the end

Meanwhile, Raj goes on a date - while
> this was better than most of this season Raj's bits, the Raj portion of
> this show still needs to be improved markedly.. :/

Having him go on vacation to India and not hear from him for a few
episodes would be a good start.
>
> Pysch (recorded) - "Office Space". Gus (being a spaz) accidentally
> implicates himself in the murder of his boss, which draws Shawn in to
> bailing him out, which then draws Henry, Juliette, and ultimately even
> Woody The Coroner, in to the deception.
> Wow, this episode was wacky - but *good* wacky!! :) I think they

yes

> spoofed *both* "Office Space" and "Glengarry Glen Ross" in this one. And
> great use of David Koechner and Michael MgGlone and Zahf Paroo as
> guest-stars (I'd also love to know who played the hot little assistant
> of the murdered boss - from EpGuides, it looks like her name is Allie
> Bertram...).

http://www.imdb.com/name/...
Looks like you can watch her in a dance competition
http://2.bp.blogspot.com/_Skoh-lE8sO0/SRu7vgsWz3I/AAAAAAAAPyk/s...
/s400/Solo+Allie2.jpg

But another Canadian Bertram actress? What are the odds she's related
to Trance Gemini?


> P.S. Woody actually even got a legitimately funny line this episode!!
> Next week looks like another hoot, as Gus becomes a D.J.!!
>
>
> Vegas - A mostly satisfying conclusion to this series (but how they left
> Jack Lamb and Mia kind of sucked... :( ). Anyway, I'm of the opinion
> that CBS made a mistake

in ever allowing this vile putrid Clodreamer level disgusting garbage on
the air.

--
"Every time a Kardashian gets a TV show, an angel dies."

Thanatos

5/12/2013 2:37:00 AM

0

In article <anim8rfsk-FA4BAA.19152911052013@news.easynews.com>,
anim8rFSK <anim8rfsk@cox.net> wrote:

> In article
> <ijball-NO_SPAM-D3F6AE.09235911052013@news.eternal-september.org>,
> "Ian J. Ball" <ijball-NO_SPAM@mac.invalid> wrote:
>
> > In article <kmli2a$kj3$1@dont-email.me>, "Obveeus" <Obveeus@aol.com>
> > wrote:
> >
> > > What did you watch?
> >
> > On a day I wanted to run errands, but was out of gas (physically), I
> > watched:
> >
> >
> > The Big Bang Theory (recorded) - "The Love Spell Potential". Decent
> > episode in which Penny, Amy and Bernadette join Sheldon and Leonard's,
> > with Wolowitz as Dungeon Master!! D&D game - Simon Helberg is
> > surprisingly deft at impressions!
>
> Good stuff until the end
>
> > Meanwhile, Raj goes on a date - while this was better than most
> > of this season Raj's bits, the Raj portion of this show still needs
> > to be improved markedly.. :/
>
> Having him go on vacation to India and not hear from him for a few
> episodes would be a good start.

And then he comes back with Priya, easily the hottest of the BBT women.
Or maybe he stays in India and sends Priya back in his place. Yeah, that
works better.