Basic question about Fixnum & Integer

Hi –

On Tue, 17 Jan 2006, David V. wrote:

On Tue, 17 Jan 2006 04:05:00 +0100, [email protected] wrote:

Or maybe not. I’ve heard extremely little about anyone actually using
any of the libraries that make block-scoped core changes possible.
Maybe there isn’t all that great a demand for orderly ways to do it.

Well d’oh. They’re rare, and they usually give unconventional behaviour to
existing code, I’d be very surprised if they were present in stable
prouction-code due to the risks involved.

I think we’re talking about two different things. I’m referring to
Ruby Behaviors, Import Module, and a third project whose name I can’t
remember but which does something similar: allow for temporary changes
to core classes.

David


David A. Black
[email protected]

“Ruby for Rails”, from Manning Publications, coming April 2006!

Is it true that RubyGems requires mathn? It seems so to me:

gus@guslaptop ~]ruby -e ‘p(5.lcm(3))’
-e:1: undefined method `lcm’ for 5:Fixnum (NoMethodError)
gus@guslaptop ~]ruby -rubygems -e ‘p(5.lcm(3))’
15
gus@guslaptop ~]ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
gus@guslaptop ~]gem -v
0.8.11

That gives me somewhat of an uneasy feeling. How many core tampering
libraries does RubyGems requires that may make me rely on methods which
are not really in the core?

Guillaume.

Hi –

On Wed, 18 Jan 2006, David V. wrote:

Heh, apparently, I had the standard modification of existing classes in mind,
without extra scoping libraries all the time. Happens. I blame the caffeine.

My segue from the first of those topics to the second may have been
unclear. I agree that changing core/standard classes, in code that is
going to be shared, is a bad idea. My first round of thinking through
this problem (expressed in ruby-talk:14556) led me to write Ruby
Behaviors, the main positive effect of which (since it’s not much more
than a proof-of-concept library) was to spark a discussion at RubyConf
2001 about selector namespaces… and hopefully that will bear fruit
in Ruby 2.x.

David


David A. Black
[email protected]

“Ruby for Rails”, from Manning Publications, coming April 2006!

Guillaume M. wrote:

Is it true that RubyGems requires mathn? It seems so to me:

No, it does not.

$ ruby -rubygems -e ‘p $".include?(“mathn.rb”)’
false

But it does require ‘time’,
which requires ‘parsedate’,
which requires ‘date/format’,
which requires ‘rational’,
which adds the ‘lcm’ method).

Any of the standard libraries (e.g. time, parsedate, time/format) may
load things that you haven’t explicitly asked for.

– Jim W.

On Jan 17, 2006, at 4:44 PM, Guillaume M. wrote:

The core is always available. You can read the docs here:
Thanks for the references.
from (irb):18
from :0
This is too simple to get wrong?

It doesn’t require mathn, it requires rational.rb

irb(main):013:0> 1/2
=> 0
irb(main):014:0> require ‘rubygems’
=> true
irb(main):015:0> 1/2
=> 0
irb(main):016:0> exit

logan:/Users/logan% ruby -e ‘p(5.lcm(3))’
-e:1: undefined method `lcm’ for 5:Fixnum (NoMethodError)
logan:/Users/logan% ruby -rubygems -e ‘p(5.lcm(3))’
15
logan:/Users/logan% ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
logan:/Users/logan% gem -v
0.8.10

irb(main):001:0> old_features = $LOADED_FEATURES.dup
=> [“irb.rb”, “e2mmap.rb”, “irb/init.rb”, “irb/context.rb”, “irb/
workspace.rb”, “irb/extend-command.rb”, “irb/ruby-lex.rb”, “irb/
slex.rb”, “irb/ruby-token.rb”, “irb/input-method.rb”,
“readline.bundle”, “irb/locale.rb”, “tempfile.rb”, “delegate.rb”,
“tmpdir.rb”, “irb/completion.rb”]
irb(main):002:0> require ‘ubygems’
=> true
irb(main):003:0> new_features = $LOADED_FEATURES - old_features
=> [“ubygems.rb”, “rubygems.rb”, “rbconfig.rb”, “rubygems/
rubygems_version.rb”, “rubygems/source_index.rb”, “rubygems/
user_interaction.rb”, “forwardable.rb”, “rubygems/specification.rb”,
“date.rb”, “rational.rb”, “date/format.rb”, “rubygems/version.rb”,
“rubygems/custom_require.rb”]