[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Execute ruby commands in a program

Haze Noc

8/18/2007 4:17:00 PM

Ok so lets say i have a program, And within the program i call a command
such as Ruby: <command>

Is there anyway to be able to run live ruby code and print the answers
(i dont really know how to put it) so like..

Ruby: name = 'john'; puts "Hi" if name == 'john'
Program: Hi


Sounds weird i know, But if Anyone out there understands me that would
be great..

I want to stay away from shell one liners like ruby -e "code here"

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

9 Answers

Chris

8/18/2007 5:25:00 PM

0

Um, this sounds like 'irb'. Depending on what OS you're on and how
you installed ruby, you should just be able to type 'irb' at the
command-line. That sounds like what you're after.

On Aug 18, 11:16 am, Haze Noc <h...@the-c0re.org> wrote:
> Ok so lets say i have a program, And within the program i call a command
> such as Ruby: <command>
>
> Is there anyway to be able to run live ruby code and print the answers
> (i dont really know how to put it) so like..
>
> Ruby: name = 'john'; puts "Hi" if name == 'john'
> Program: Hi
>
> Sounds weird i know, But if Anyone out there understands me that would
> be great..
>
> I want to stay away from shell one liners like ruby -e "code here"
>
> Thanks in advance
> --
> Posted viahttp://www.ruby-....


Daniel Martin

8/18/2007 5:59:00 PM

0

Haze Noc <h4z3@the-c0re.org> writes:

> Is there anyway to be able to run live ruby code and print the answers
> (i dont really know how to put it) so like..
>
> Ruby: name = 'john'; puts "Hi" if name == 'john'
> Program: Hi
>
> Sounds weird i know, But if Anyone out there understands me that would
> be great..
>
> I want to stay away from shell one liners like ruby -e "code here"

I have a bit of trouble understanding what it is you want to have
happen, especially since you specifically wish to avoid 1-liners.

Is "irb" (bundled with ruby) what you want?

Absent that, at the shell you can just run "ruby", type some ruby
code, then type
__END__
on a line by itself, (that's two underscores, then END, then two more
underscores) and the code will then run.

Is either of this what you wanted?

--
s=%q( Daniel Martin -- martin@snowplow.org
puts "s=%q(#{s})",s.to_a.last )
puts "s=%q(#{s})",s.to_a.last

Haze Noc

8/18/2007 6:35:00 PM

0

Sorry its quite hard to explain, Its not IRB, because i want to actually
run a command from within another ruby script.. Lets say i wanted to do
a 1 liner from within the program i could do something like..

me: ruby puts "Hello"
script runs `ruby -e "puts 'Hello'"
Program: Hello

But i didn't really want to do any 1 liners, althouth if i did, lets say
i have

while msg = gets
if msg =~ /^ruby (.+)/i
msg.gsub!(/\"/, "'")
message = `ruby -e "#{$1}"`
puts message
end
end

and input was..

puts 'hello'

How could i return the input?
--
Posted via http://www.ruby-....

John Joyce

8/18/2007 6:41:00 PM

0


On Aug 18, 2007, at 1:34 PM, Haze Noc wrote:

> Sorry its quite hard to explain, Its not IRB, because i want to
> actually
> run a command from within another ruby script.. Lets say i wanted
> to do
> a 1 liner from within the program i could do something like..
>
> me: ruby puts "Hello"
> script runs `ruby -e "puts 'Hello'"
> Program: Hello
>
> But i didn't really want to do any 1 liners, althouth if i did,
> lets say
> i have
>
> while msg = gets
> if msg =~ /^ruby (.+)/i
> msg.gsub!(/\"/, "'")
> message = `ruby -e "#{$1}"`
> puts message
> end
> end
>
> and input was..
>
> puts 'hello'
>
> How could i return the input?
> --
> Posted via http://www.ruby-....
>
look up eval

Haze Noc

8/18/2007 7:06:00 PM

0

John Joyce wrote:
> On Aug 18, 2007, at 1:34 PM, Haze Noc wrote:
>
>> But i didn't really want to do any 1 liners, althouth if i did,
>>
>> and input was..
>>
>> puts 'hello'
>>
>> How could i return the input?
>> --
>> Posted via http://www.ruby-....
>>
> look up eval


Thanks, i looked it up and coded something pretty much the same except
something like message = eval("#{$1}").. when i print out the return it
just print nil
--
Posted via http://www.ruby-....

Simon Krahnke

8/19/2007 11:51:00 AM

0

* Haze Noc <h4z3@the-c0re.org> (21:05) schrieb:

> Thanks, i looked it up and coded something pretty much the same except
> something like message = eval("#{$1}").. when i print out the return it
> just print nil

What did you expect it to print?

mfg, simon .... l

Lamont Cranston

1/26/2011 11:56:00 PM

0

On 1/26/2011 12:39 PM, Billary wrote:
> On Jan 25, 6:27 pm, Lamont Cranston<Lamont.Crans...@FogYourMind.com>
> wrote:
>> On 1/24/2011 3:40 AM, Billary wrote:
>>
>>> Before computers& the internet. It was common for people of that era
>>> to fake resumes, military service, employment records, college
>>> degrees, places of birth, dates of birth, marriages, divorces, deaths,
>>> social security numbers etc. Just ask the phoney Democrat "Vietnam
>>> Vet" in Connecticut, Richard Blumenthal.
>>
>>> FACT: There are NO WITNESSES who can place "Ann" Stanley Dunham,
>>> pregnant, in Honolulu in August 1961. Even Time Magazine could not
>>> find any.
>>
>> FACT: The current Governor of Hawaii was present in Honolulu when
>> Stanley Dunham gave birth to Obama.
>
> Then produce said Governor as a witness to the purported miraculous
> birth asshole.

http://www.csmonitor.com/USA/Politics/The-Vote/2010/1228/Why-Hawaii-Gov.-Neil-Abercrombie-is-taking-on-anti-Obam...

....

On CNN yesterday, Abercrombie acknowledged that more documentation may
not satisfy the birthers, but said he was acting because of his personal
disgust with the claims and the fact that he knew Obama's parents back
in college when Obama was born and is deeply offended at claims he knows
to be false.

"It's a matter of principle with me. I knew his mom and dad. I was
here when he was born. Anybody who wants to ask a question honestly
could have had their answer already," he told CNN.

....

Fuck off, Shill, you psychokooker birther.

Doctor Gaius Baltar

1/27/2011 4:18:00 PM

0

On Jan 26, 6:55 pm, Lamont Cranston <Lamont.Crans...@FogYourMind.com>
wrote:
> On 1/26/2011 12:39 PM, Billary wrote:
>
>
>
> > On Jan 25, 6:27 pm, Lamont Cranston<Lamont.Crans...@FogYourMind.com>
> > wrote:
> >> On 1/24/2011 3:40 AM, Billary wrote:
>
> >>> Before computers&    the internet. It was common for people of that era
> >>> to fake resumes, military service, employment records, college
> >>> degrees, places of birth, dates of birth, marriages, divorces, deaths,
> >>> social security numbers etc. Just ask the phoney Democrat "Vietnam
> >>> Vet" in Connecticut, Richard Blumenthal.
>
> >>> FACT: There are NO WITNESSES who can place "Ann" Stanley Dunham,
> >>> pregnant, in Honolulu in August 1961. Even Time Magazine could not
> >>> find any.
>
> >> FACT:  The current Governor of Hawaii was present in Honolulu when
> >> Stanley Dunham gave birth to Obama.
>
> > Then produce said Governor as a witness to the purported miraculous
> > birth asshole.
>
> http://www.csmonitor.com/USA/Politics/The-Vote/2010/1228/Wh......
>
> ...
>
> On CNN yesterday, Abercrombie acknowledged that more documentation may
> not satisfy the birthers, but said he was acting because of his personal
> disgust with the claims and the fact that he knew Obama's parents back
> in college when Obama was born and is deeply offended at claims he knows
> to be false.
>
>   "It's a matter of principle with me. I knew his mom and dad. I was
> here when he was born. Anybody who wants to ask a question honestly
> could have had their answer already," he told CNN.
>
> ...
>
> Fuck off, Shill, you psychokooker birther.

I was here where he was born ***NOT*** I was there when he was born.

You got nothing. Never did.

Truman Kaputt

1/29/2011 12:11:00 AM

0

On 1/25/2011 3:27 PM, Lamont Cranston wrote:
> On 1/24/2011 3:40 AM, Billary wrote:
>> Before computers& the internet. It was common for people of that era
>> to fake resumes, military service, employment records, college
>> degrees, places of birth, dates of birth, marriages, divorces, deaths,
>> social security numbers etc. Just ask the phoney Democrat "Vietnam
>> Vet" in Connecticut, Richard Blumenthal.
>>
>> FACT: There are NO WITNESSES who can place "Ann" Stanley Dunham,
>> pregnant, in Honolulu in August 1961. Even Time Magazine could not
>> find any.
>
> FACT: The current Governor of Hawaii

SAYS he...

> was present in Honolulu when
> Stanley Dunham gave birth to Obama.

He can say lots of shit, Cuntston - doesn't make any of it true.