[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03861] main.method

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-07-06 10:04:01 UTC
List: ruby-talk #3861
How I can make this work, that is to print blop and blop instead of blop and
burp? How to call methods defined in Object just like methods in any other
class? That means the method don't get wrong self?

I thought main.burp would deal with the problem, but it seems that I can't
access main.

This mail relates to [ruby-talk:03846] -thread, but is the same thing from
another point of view.

	- Aleksi

class Fish
  def initialize
    @burp = "burp"
  end
  def burp
    puts globalBurp
    puts main.globalBurp
  end
end

@burp = "blop"

def globalBurp
  p self
  @burp
end

puts globalBurp, "\n"

puts "now I expect fish to (blobal) burp, which means 'blop'"
Fish.new.burp

######################
Outputs:

#<Object: @burp="blop">
blop

now I expect fish to (blobal) burp, which means 'blop'
#<Fish: @burp="burp">
burp
main.rb:7:in `burp': undefined local variable or method `main' for
#<Fish:0x2473c8> (NameError)
        from main.rb:21

In This Thread

Prev Next