Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Ruby is pretty cool, but tutorial lied.
Index -> Programming, Ruby -> Ruby Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mirhagk




PostPosted: Sat Jan 01, 2011 5:58 pm   Post subject: Ruby is pretty cool, but tutorial lied.

Ruby's get started in 20 minutes tutorial says this is possible

Ruby:

class Fixnum
  # You can, but please don't do this
  def +( other )
    self - other
  end
end


but if I try to do it, the interactive ruby epic fails and closes. Why is this?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jan 01, 2011 6:05 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

works just fine
code:

irb(main):001:0> class Fixnum
irb(main):002:1>   def +(other)
irb(main):003:2>     self - other
irb(main):004:2>   end
irb(main):005:1> end
=> nil
irb(main):006:0>
irb(main):005:0* 2 + 2
=> 0
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mirhagk




PostPosted: Sat Jan 01, 2011 10:58 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

after defining the class it returns nil, then freaks out with something about method not found, then 30 lines of from C:\ruby192\lib\ruby\.... etc
then quits.
Tony




PostPosted: Sat Jan 01, 2011 11:26 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

I can't tell you much without you being more specific about that method and those lines.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mirhagk




PostPosted: Sat Jan 01, 2011 11:55 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

=> nil
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:8446:in `_rl_find_next_mbchar'
: undefined method `force_encoding' for nil:NilClass (NoMethodError)
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1692:in `block in
expand_prompt'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1676:in `each'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1676:in `expand_p
rompt'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1765:in `rl_expan
d_prompt'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1790:in `rl_set_p
rompt'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4718:in `readline
'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/readline.rb:40:in `readline'
from C:/Ruby192/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_i
nput'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
from C:/Ruby192/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
from C:/Ruby192/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels)
in each_top_level_statement'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top
_level_statement'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
from C:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_st
atement'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:70:in `block in start'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:69:in `catch'
from C:/Ruby192/lib/ruby/1.9.1/irb.rb:69:in `start'
from C:/Ruby192/bin/irb:12:in `<main>'

thats the response, then im back at the command line (after ruby exits)
Tony




PostPosted: Sun Jan 02, 2011 12:10 am   Post subject: RE:Ruby is pretty cool, but tutorial lied.

Maybe try with --noreadline flag on irb?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mirhagk




PostPosted: Sun Jan 02, 2011 6:46 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

k i tried to redefine the -, and it quit, this time it said stack level too deep


EDIT: and how do I do the noreadline thing?
jcollins1991




PostPosted: Sun Jan 02, 2011 6:54 pm   Post subject: Re: Ruby is pretty cool, but tutorial lied.

code:
irb --noreadline
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Sun Jan 02, 2011 9:27 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

thank you, that worked, can you explain what the noreadline thing does?
Tony




PostPosted: Sun Jan 02, 2011 11:19 pm   Post subject: RE:Ruby is pretty cool, but tutorial lied.

It disables readline, which is where the fatal exception seems to occur. Readline allows for in-line editing such as tab completion and history.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: