Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Help with "rubyizing" script
matthew.moss.coder
2/6/2006 3:22:00 PM
> Then I don't really like the (0..x) stuff. As I said, I tried times, but
> that only counts up to w-1. Hm. And (w+1).times is even uglier. Anything
> better than that? There's probably a better way get a list of all
> members of [0..w] x [0..w] x [0..w] ("x" being the cartesian product),
> from which one could then select() the ones that fit. Any ideas on that?
(0..x) forms a range object which can be rather useful. If you don't
like that, you can try 0.upto(x), which is less compact but maybe will
look better for you? I don't know anything offhand for a cartiesian
product, but it wouldn't be that difficult to write such a method that
yielded to a block.
> Oh, and a last thing: I'd rather write a.sqrt and was disappointed this
> doesn't work. However, ruby-doc _does_ mention Math#sqrt, and even
> Math#sqrt!:
>
http://ruby-doc.org/core/classes/Math.ht...
> It took me a while to find out those are from Complex. Would it be
> possible to state this more clearly somewhere? Better yet, make a.sqrt work?
Ruby makes extending classes easy...
class Numeric
def sqrt
Math.sqrt(self)
end
end
3.sqrt
=> 1.73205080756888
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Help with "rubyizing" script
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password