> > validate do |value|
> > raise Puppet::Error, "number has to be numeric, not #{value}"
> unless value =~ /^[0-9]+$/
> > - raise Puppet::Error, "number #{value} out of range" unless
> (0...2**16).include?(Integer(value))
>
> just out of curiosity: Will (0...2**16) generate just a huge array with
> include? beeing extreamly slow or does ruby handle ranges of integers
> differently?
>
It's good. Ranges aren't arrays (you can convert them to arrays, but it
doesn't happen implicitly); they are two element structures (a low
value/high value pair). That allows you to do things like 1.14..3.14, and
5..-1 which wouldn't work as arrays. As for the performance aspect, go into
irb and try:
(0..2**2000).include? 1234
It comes back immediately without prompting you to purchase more ram. :)
It definitely pays to be on the lookout for things like this because small
differences in idiom can (like the case in rails a few years ago
http://kevin.scaldeferri.com/blog/, or our make-and-throw-away-arrays issue
in rest #6257) be significant performance hits, so thanks for asking.
-- M
------------------------------------------------------------
When in trouble or in doubt, run in circles,
scream and shout. -- 1920's parody of the
maritime general prudential rule
------------------------------------------------------------
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.