Division hangs irb

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

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.fourmond.neuf.fr/

Thanks Vince, cleared that up

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

Ashley

···

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

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

···

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

) 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/~kbloom1/

to_f vs /

I'll add the appriopriate params to show you what the parser sees:

(DateTime.now - Date.new(2006,9,15)).to_f ( /30 ) # /30 is taken in as a
single param because of lack of space and because you're calling to_f

10 /5 => 10./(5) # In this case, / IS the method call, as 10 is not a
method, so the parser figures this out correctly.

Either way, just put spaces there. It looks better and is easier to read.

Jason

···

On 12/19/06, Ashley Moran <work@ashleymoran.me.uk> wrote:

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 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

···

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

--
Vincent Fourmond, PhD student
http://vincent.fourmond.neuf.fr/

One more thing to help you understand:

(DateTime.now - Date.new(2006,9,15)).to_f() /30 # this will work

···

On 12/19/06, Jason Roelofs <jameskilton@gmail.com> wrote:

On 12/19/06, Ashley Moran <work@ashleymoran.me.uk> wrote:

>
> 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

to_f vs /

I'll add the appriopriate params to show you what the parser sees:

(DateTime.now - Date.new(2006,9,15)).to_f ( /30 ) # /30 is taken in as a
single param because of lack of space and because you're calling to_f

10 /5 => 10./(5) # In this case, / IS the method call, as 10 is not a
method, so the parser figures this out correctly.

Either way, just put spaces there. It looks better and is easier to read.

Jason

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