[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Division hangs irb

Ashley Moran

12/19/2006 1:47:00 PM

Anyone know why the first three of these calculations works on my irb
(on intel OS X 10.4.8), but the last one silently hangs?

>> (DateTime.now - Date.new(2006,9,15)).to_f / 30
=> 3.18572031018981
>> (DateTime.now - Date.new(2006,9,15)).to_f/ 30
=> 3.18572102628549
>> (DateTime.now - Date.new(2006,9,15)).to_f/30
=> 3.18572174544174
>> (DateTime.now - Date.new(2006,9,15)).to_f /30
<not a lot happening>
^C

Ashley


5 Answers

Vincent Fourmond

12/19/2006 2:06:00 PM

0

Ashley Moran wrote:
> Anyone know why the first three of these calculations works on my irb
> (on intel OS X 10.4.8), but the last one silently hangs?
>
>>> (DateTime.now - Date.new(2006,9,15)).to_f / 30
> => 3.18572031018981
>>> (DateTime.now - Date.new(2006,9,15)).to_f/ 30
> => 3.18572102628549
>>> (DateTime.now - Date.new(2006,9,15)).to_f/30
> => 3.18572174544174
>>> (DateTime.now - Date.new(2006,9,15)).to_f /30

Irb takes the latter as the beginning of a regular expression for the
first argument of to_f:

>> (DateTime.now - Date.new(2006,9,15)).to_f /30
/
ArgumentError: wrong number of arguments (1 for 0)
from (irb):10:in `to_f'
from (irb):10
from /usr/lib/ruby/1.8/rational.rb:520

Cheers,

Vince
--
Vincent Fourmond, PhD student
http://vincent.fourmon...

Ashley Moran

12/19/2006 2:11:00 PM

0


On 19 Dec 2006, at 14:06, Vincent Fourmond wrote:

> Irb takes the latter as the beginning of a regular expression for
> the
> first argument of to_f:
>
>>> (DateTime.now - Date.new(2006,9,15)).to_f /30
> /
> ArgumentError: wrong number of arguments (1 for 0)
> from (irb):10:in `to_f'
> from (irb):10
> from /usr/lib/ruby/1.8/rational.rb:520
>
> Cheers,
>
> Vince


Thanks Vince, cleared that up

I wondered why that didn't work but "10 /5" did

Ashley

Ken Bloom

12/19/2006 3:08:00 PM

0

On Tue, 19 Dec 2006 23:06:05 +0900, Vincent Fourmond wrote:

> Ashley Moran wrote:
>> Anyone know why the first three of these calculations works on my irb
>> (on intel OS X 10.4.8), but the last one silently hangs?
>>
>>>> (DateTime.now - Date.new(2006,9,15)).to_f / 30
>> => 3.18572031018981
>>>> (DateTime.now - Date.new(2006,9,15)).to_f/ 30
>> => 3.18572102628549
>>>> (DateTime.now - Date.new(2006,9,15)).to_f/30
>> => 3.18572174544174
>>>> (DateTime.now - Date.new(2006,9,15)).to_f /30
>
> Irb takes the latter as the beginning of a regular expression for the
> first argument of to_f:

....therefore IRB is still waiting for input. But you should see the a
prompt when you hit enter, with a different ending character (/ instead of
>) to indicate that IRB is still waiting for input.

>>> (DateTime.now - Date.new(2006,9,15)).to_f /30
> /
> ArgumentError: wrong number of arguments (1 for 0)
> from (irb):10:in `to_f'
> from (irb):10
> from /usr/lib/ruby/1.8/rational.rb:520
>
> Cheers,
>
> Vince



--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Vincent Fourmond

12/19/2006 3:24:00 PM

0

Ken Bloom wrote:
> On Tue, 19 Dec 2006 23:06:05 +0900, Vincent Fourmond wrote:
>
>> Ashley Moran wrote:
>>> Anyone know why the first three of these calculations works on my irb
>>> (on intel OS X 10.4.8), but the last one silently hangs?
>>>
>>>>> (DateTime.now - Date.new(2006,9,15)).to_f / 30
>>> => 3.18572031018981
>>>>> (DateTime.now - Date.new(2006,9,15)).to_f/ 30
>>> => 3.18572102628549
>>>>> (DateTime.now - Date.new(2006,9,15)).to_f/30
>>> => 3.18572174544174
>>>>> (DateTime.now - Date.new(2006,9,15)).to_f /30
>> Irb takes the latter as the beginning of a regular expression for the
>> first argument of to_f:
>
> ...therefore IRB is still waiting for input.

But you should see the a
> prompt when you hit enter, with a different ending character (/ instead of
>> ) to indicate that IRB is still waiting for input.

Actually, no: I did type the /. This way, I finish the regexp started
on the previous line, and the expression is parsed and causes an error.
By the way, is there a way to define a secondary prompt in IRB ?

Vince

--
Vincent Fourmond, PhD student
http://vincent.fourmon...

Kalman Noel

12/19/2006 5:39:00 PM

0

Vincent Fourmond:
> By the way, is there a way to define a secondary prompt in IRB ?

Maybe that is :PROMPT_S.

IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_I => # Insert
:PROMPT_C => # your
:PROMPT_N => # favorite
:PROMPT_S => # strings
:RETURN => # here
}
IRB.conf[:PROMPT_MODE] = :CUSTOM

Kalman