[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Calling a Method

Ron Green

9/17/2008 4:28:00 PM

If I have a file that contains a method that takes one parameter. and
I want to call the method from the command line, how do you do that?
I know how to run a script from the command line but not how to call a
method.

5 Answers

Nathan Powell

9/17/2008 4:33:00 PM

0

On Thu, Sep 18, 2008 at 01:28:15AM +0900, Rong wrote:
> If I have a file that contains a method that takes one parameter. and
> I want to call the method from the command line, how do you do that?
> I know how to run a script from the command line but not how to call a
> method.

I'll be interested to see if there is a better way to do this...

npowell@delilah ~ $ cat test.rb
class Foo
def bar
puts "Oh Hai!"
end
end
npowell@delilah ~ $ ruby -e 'require "test"; f = Foo.new; f.bar;'
Oh Hai!

--
nathan
nathan_at_nathanpowell_dot_org

Trust no thought arrived at sitting down.
~ George Sheehan
------------------------------------

Henning Bekel

9/17/2008 5:01:00 PM

0

Rong wrote:

> If I have a file that contains a method that takes one parameter. and
> I want to call the method from the command line, how do you do that?
> I know how to run a script from the command line but not how to call a
> method.

Is this what you mean?

henning@box:~$ cat test.rb
def bar(p=ARGV[0])
puts "bar called with parameter '#{p}'"
end
henning@box:~$ ruby -rtest -e 'bar' Hello
bar called with parameter 'Hello'

Nathan Powell

9/17/2008 5:03:00 PM

0

On Thu, Sep 18, 2008 at 01:57:31AM +0900, Henning Bekel wrote:
> henning@box:~$ cat test.rb
> def bar(p=ARGV[0])
> puts "bar called with parameter '#{p}'"
> end
> henning@box:~$ ruby -rtest -e 'bar' Hello
> bar called with parameter 'Hello'

Nice. I should have looked at the Ruby man page. -r makes sense.

Though I would have done this:

npowell@delilah ~ $ ruby -r test -e 'bar("Oh Hai")'
Oh Hai

Just to keep from having to add the ARGV[0] as the default value.
--
nathan
nathan_at_nathanpowell_dot_org

Now I know what a statesman is; he's a dead politician. We need more statesmen.
~ Bob Edwards
------------------------------------

Ron Green

9/17/2008 10:48:00 PM

0

Thanks Nathan.

On Sep 17, 12:02=A0pm, Nathan Powell <nat...@nathanpowell.org> wrote:
> On Thu, Sep 18, 2008 at 01:57:31AM +0900, Henning Bekel wrote:
> > henning@box:~$ cat test.rb
> > def bar(p=3DARGV[0])
> > =A0 puts "bar called with parameter '#{p}'"
> > end
> > henning@box:~$ ruby -rtest -e 'bar' Hello
> > bar called with parameter 'Hello'
>
> Nice. I should have looked at the Ruby man page. =A0-r makes sense.
>
> Though I would have done this:
>
> npowell@delilah ~ $ ruby -r test -e 'bar("Oh Hai")'
> Oh Hai
>
> Just to keep from having to add the ARGV[0] as the default value.
> --
> nathan
> nathan_at_nathanpowell_dot_org
>
> Now I know what a statesman is; he's a dead politician. We need more stat=
esmen.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0~ Bob Edwards
> ------------------------------------

CB@PrayForMe.com

3/25/2010 10:43:00 AM

0


"Ron" <roneal1554@att.net> wrote in message
news:c6f40b8b-8d7a-4fda-9115-50ebcccc9f26@q16g2000yqq.googlegroups.com...
On Mar 24, 7:03 pm, "CB" <C...@PrayForMe.com> wrote:
> "Arizona Bushwhacker" <ArizonaBushwhac...@cox.net> wrote in message
>
> news:Huxqn.429$XI1.224@newsfe20.iad...
>
> > This is fucking great!
> > Some terrorist tea-bagger is saying that there is NO evidence that
> > tea-baggers are racist. Yet half of his subject title is about race.
>
> CBS propagates racism, just as Dim Libs have done
>
> CB
> Race baiting Libs projecting their
> hatehttp://www.youtube.com/watch?v=8...
.
.
Re: CBS reports on Dims calling Tea Party racists...

In your post, you gave a YouTube video of some of Carter's statements
about Tea Party participants

In the YouTube video you cited, Carter states (with MY CAPS)

"I think that an overwhelming portion of the INTENSELY DEMONSTRATED
ANIMOSITY toward President Barack Obama is based on the fact that he
is a black man."

During that video, a rectangular baloon at Carter's mouth says Carter
denied having said this. He did not deny saying it, but corrected a
reporter who stated:

"You said OVERALL that you thought the protesters were upset that
there was a black president, that there was racism involved....."

Carter cut her off and corrected her. He said the VITUPERATIVE
attacks were racially motivated. For your edification, vituperative
means: Criticism or invective which is sustained and considered to be
OVERLY HARSH. That is to say, intensely demonstrated animosity: that
which comes from the fringe elements. Carter makes this very clear.


There are two videos of these interviews that can be seen at one URL

http://www.abovetopsecret.com/forum/thread...

So much of what I see posted by the Right on this group is based on a
child like interpretation of what is actually said. I hate to say it
(but secretly enjoy it): RightWingers posting on this group are
stupid. Illiterate. Gullible.

RO

_______________________________________________

The hate filled arrogance of the Left contrives to label Tea Party members
as violent when the only violent acts have come from SEIU union thugs
wearing purple who beat up a Black Conservative.

Obama has surrounded him self with 'violent' radicals who committed
terrorist bombings!