basic question about Fixnum & Integer

D

dblack

Hi --

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
(e-mail address removed)

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
 
D

David Vallner

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


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

David Vallner
 
D

dblack

Hi --

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
(e-mail address removed)

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
 
G

Guillaume Marcais

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

Logan Capaldo

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.

Tom said:
Thanks for the references.
For some reason I can't get my installation of Ruby to do what the
examples show:
6.lcm 7
return
NoMethodError: undefined method `lcm' for 6:Fixnum
from (irb):17
from :0
NoMethodError: undefined method `lcm' for 6:Fixnum
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"]
 
J

Jim Weirich

Guillaume said:
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 Weirich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,542
Members
48,282
Latest member
PrincessX3

Latest Threads

Top