[#964] Bastion or SecurityManager for Ruby? — Clemens Hintze <clemens.hintze@...>

Hi,

15 messages 1999/12/10

[#989] a question about to_i — Friedrich Dominicus <Friedrich.Dominicus@...>

Sorry, I'm quite new to ruby. But I encounterd the following problem. If

17 messages 1999/12/19

[ruby-talk:01002] Re: a question about to_i

From: Friedrich Dominicus <Friedrich.Dominicus@...>
Date: 1999-12-20 05:59:09 UTC
List: ruby-talk #1002
some solutions ommitted.
> --
>          yashi
> 
> class String
>   def to_float
>     return to_f if self =~ /^[-+]?((\d+)?(\.\d+))|((\d+)(\.\d+)?)([eE][-+]\d+)?$/
>     raise "fail at convert string to float"
>   end
>   def to_int
>     return to_i if self =~ /^[-+]?(\d+)$/
>     raise "fail at convert string to int"
>   end
> end

This does not work for strings like foo124. this will not be converted
althought one can argue that it could work. I'm no sure about this but I
think it's cleaner not to work here. (But that's just my opinion YMMV)

Regards
Friedrich

In This Thread