[#403837] Why none of the block giving the expected output with the "enumerator"? — Arup Rakshit <lists@...>

Why none of the block giving the expected output with the "enumerator"?

9 messages 2013/02/02

[#403870] Confusion with Enum#with_object block argument construct — Arup Rakshit <lists@...>

C:\>irb

9 messages 2013/02/03

[#403920] Character classes use in Ruby — Love U Ruby <lists@...>

Can anyone help me by giving an explanatory example of each of the

13 messages 2013/02/04

[#403935] How to stop page loading using selenium-web driver? — Love U Ruby <lists@...>

How to stop page loading using selenium-web driver?

11 messages 2013/02/04

[#403972] Ruby could recognize the values when putting into a webpage text filed. — Love U Ruby <lists@...>

SGksCgpJIGhhdmUgc29tZSB2YWx1ZXMgaW4gbXkgRXhjZWwgYXMgYmVsb3c6

9 messages 2013/02/05

[#403986] old syntax? what's going on here — tamouse mailing lists <tamouse.lists@...>

I have this in a _spec.rb file: (a gem I inherited at work)

11 messages 2013/02/05

[#404005] Implementing DRY with a function call — Rob Marshall <lists@...>

Hi,

12 messages 2013/02/05

[#404006] using an instance variable inside a method — FirstName Surname <lists@...>

Hello.

19 messages 2013/02/05

[#404021] Not able get the label text incurred with <input> element — Love U Ruby <lists@...>

I do have a below `HTML`:

18 messages 2013/02/05

[#404025] Symbol.defined? — Student Jr <lists@...>

Symbol deserialization from external sources is now known to be

15 messages 2013/02/06

[#404058] Ruby 1.9.3-p362 on Mac OSX — Peter Bailey <lists@...>

Hi,

13 messages 2013/02/06

[#404082] Problem building Ruby 1.9.3 patchlevel 385 under AIX 7.1 — Ruby Student <ruby.student@...>

Hello World!

10 messages 2013/02/06

[#404101] Issues from an extreme beginner — Bruce Palmer <lists@...>

Hey guys, great to be part of such a great community! I look forward to

19 messages 2013/02/07
[#404104] Re: Issues from an extreme beginner — Bruce Palmer <lists@...> 2013/02/07

Ahh, thank you Matthew! That was just the push I needed!

[#404208] elegant way to determine if something is defined — tamouse mailing lists <tamouse.lists@...>

Something like:

15 messages 2013/02/10

[#404218] Ruby Equivalent to VB's "With"? — Joel Pearson <lists@...>

I've looked around but I couldn't find anything helpful on this,

11 messages 2013/02/10

[#404235] The "ruby way" to do desktop applications? — "guirec c." <lists@...>

Hello,

17 messages 2013/02/11

[#404238] Best books for "advanced" programmers — "guirec c." <lists@...>

Hello,

18 messages 2013/02/11

[#404245] Issue with Excel column values read. — Love U Ruby <lists@...>

Hi,

22 messages 2013/02/11

[#404344] Ruby command line options s and S — Love U Ruby <lists@...>

Can anyone help me to understand the difference between s and S with

15 messages 2013/02/13

[#404386] Re: Ruby command line options s and S — "D. Deryl Downey" <me@...>

Dude!

20 messages 2013/02/14

[#404387] Ruby Multithreaded producer-consumer problem — Abhijit Sarkar <lists@...>

Hi,

26 messages 2013/02/14
[#404896] Re: Ruby Multithreaded producer-consumer problem — Abhijit Sarkar <lists@...> 2013/02/24

Bump!

[#404456] skip iteration in each loop — Saurav Chakraborty <lists@...>

I want to skip iteration for few values depending on dynamic condition.

11 messages 2013/02/15

[#404491] so, what's the proper way to replace funcionality of GOTO ? — "Stu P. D'naim" <lists@...>

I need to make few scripts for tasks I do often manually, but last time

27 messages 2013/02/15
[#404492] Re: [from BASIC to Ruby] so, what's the proper way to replace funcionality of GOTO ? — Love U Ruby <lists@...> 2013/02/15

Stu P. D'naim wrote in post #1097111:

[#404494] Re: [from BASIC to Ruby] so, what's the proper way to replace funcionality of GOTO ? — Ryan Victory <ryan@...> 2013/02/15

Love U Ruby: I'm really not sure what you meant by that response, but

[#404570] What is Ruby's default constructor? — Love U Ruby <lists@...>

Hi,

12 messages 2013/02/17

[#404632] Re: splat operator and Ruby instance variable assignments — Marc Heiler <lists@...>

Ok, understood what the guy wants ...

17 messages 2013/02/19
[#404640] Re: splat operator and Ruby instance variable assignments — Love U Ruby <lists@...> 2013/02/19

Marc Heiler wrote in post #1097736:

[#404645] Re: splat operator and Ruby instance variable assignments — Ryan Davis <ryand-ruby@...> 2013/02/19

[#404646] Re: splat operator and Ruby instance variable assignments — Love U Ruby <lists@...> 2013/02/19

Ryan Davis wrote in post #1097840:

[#404647] Re: splat operator and Ruby instance variable assignments — Peter Hickman <peterhickman386@...> 2013/02/19

On 19 February 2013 20:35, Love U Ruby <lists@ruby-forum.com> wrote:

[#404648] Re: splat operator and Ruby instance variable assignments — Love U Ruby <lists@...> 2013/02/19

Peter Hickman wrote in post #1097848:

[#404696] THE CLASS/OBJECT CHICKEN-AND-EGG PARADOX — "Xavier R." <lists@...>

Hi,

25 messages 2013/02/20
[#404699] Re: THE CLASS/OBJECT CHICKEN-AND-EGG PARADOX — Matt Mongeau <halogenandtoast@...> 2013/02/20

Maybe you could provide more detail about what you are confused about. To

[#404700] Re: THE CLASS/OBJECT CHICKEN-AND-EGG PARADOX — "Xavier R." <lists@...> 2013/02/20

Matt Mongeau wrote in post #1098058:

[#404705] Re: THE CLASS/OBJECT CHICKEN-AND-EGG PARADOX — Matt Mongeau <halogenandtoast@...> 2013/02/20

It's not really a paradox. Take for example

[#404738] backslash substitution — Mario Ruiz <lists@...>

don't know why... but this is not working

18 messages 2013/02/21

[#404809] Difference of 2 dates interms of years. — "Xavier R." <lists@...>

how can we get the experience years between two dates(ex:2012-01-11 to

13 messages 2013/02/22

[#404817] Not able to understand the difference between "||=" and "|=". — "Xavier R." <lists@...>

>> a = []

12 messages 2013/02/22

[#404839] range is not assigning to the splat variable. — Love U Ruby <lists@...>

Why splat variable couldn't take in the below two code the "range" ->

10 messages 2013/02/23

[#404842] Why class returning its own name when "include" statement? — Love U Ruby <lists@...>

I was actually playing around with the class definition return values.

16 messages 2013/02/23
[#404844] Re: Why class returning its own name when "include" statement? — Love U Ruby <lists@...> 2013/02/23

@Stefano Yes you are right. The below code is proved that.

[#404867] how to see the class creation time in Ruby? — Love U Ruby <lists@...>

In Ruby any chance to see the last-modified time of a specific class?

15 messages 2013/02/23

[#404901] Confusion with `nil` value being produced by IRB in case of Array#size manipulation. — Love U Ruby <lists@...>

enum[int] =3D obj =E2=86=92 obj

10 messages 2013/02/24

[#404921] How should I print only the last combination when using Array#combination(n) ? — Love U Ruby <lists@...>

>> a = [1,2,3]

15 messages 2013/02/24

[#405026] Please, help (GCD) greatest common divisor. — Caddy Tonks Lupin <lists@...>

Write a program to read two integers and show their greatest common

17 messages 2013/02/26

[#405059] Does this specific sound library exist? — Dirk Vogel <lists@...>

Hi there,

16 messages 2013/02/26

[#405067] Mac OS 10.8.2 and openssl — "Dr. Hegewald" <hegewald@...>

Hi everybody,

24 messages 2013/02/27

[#405079] Why `10` not returned without the `return` from the block ? — Love U Ruby <lists@...>

CODE - I

10 messages 2013/02/27

[#405107] Object track llist for a particular class. — "Xavier R." <lists@...>

Say I have created more than one instances from a particular class as

13 messages 2013/02/27

[#405145] Discussion on Ruby's `alias` — Tukai Patra <lists@...>

>> class Foo

27 messages 2013/02/28

[#405175] telnet - how to loop through commands listed in a file — Bob Ford <lists@...>

Let me first explain what I'm trying to do. I have written a very

18 messages 2013/02/28

Re: Class method's has a fuzzy meaning and a sharp meaning

From: Robert Klemme <shortcutter@...>
Date: 2013-02-23 11:53:57 UTC
List: ruby-talk #404858
On Fri, Feb 22, 2013 at 8:53 PM, Florian Gilcher <flo@andersground.net> wrote:

> Actually, I groked that concept after I understood that "instance methods"
> are actually the special ones.

I agree to all else you wrote and your examples but I disagree with
the statement above.  At least, I view this differently: all methods
(even class methods) are instance methods because they are stored in
_some_ kind of class.  The usual way to define a method is

class X
  def foo
  end
end

and

module Y
  def foo
  end
end

All instances which inherit X or Y will have the method.  Note that
this is also true if X is really Class or Module which means that
instances of X would be classes or modules.

irb(main):002:0> class Class
irb(main):003:1> def m; "this is a class method" end
irb(main):004:1> end
=> nil
irb(main):005:0> String.m
=> "this is a class method"
irb(main):006:0> Fixnum.m
=> "this is a class method"

Analogous for Module.

The distinction David is aiming at is this: method m from the example
above is the one that is fuzzily called "class method" because it can
be invoked on any class but is not necessarily defined on a class:

irb(main):007:0> Class.ancestors
=> [Class, Module, Object, Kernel, BasicObject]
irb(main):008:0> class Module
irb(main):009:1> def x; "for classes and modules" end
irb(main):010:1> end
=> nil
irb(main):011:0> String.x
=> "for classes and modules"
irb(main):012:0> Enumerable.x
=> "for classes and modules"

The strict ones are really singleton methods defined on a class object:

irb(main):013:0> def String.z; "singleton method on a class" end
=> nil
irb(main):014:0> String.z
=> "singleton method on a class"

But singleton methods can be defined on _any_ instance - a class or
module is just a special case here:

irb(main):015:0> o = Object.new
=> #<Object:0x802a6414>
irb(main):016:0> def o.s; "singleton method on a non class and non
module object" end
=> nil
irb(main):017:0> o.s
=> "singleton method on a non class and non module object"

In all cases - object, class and module - the method definition is
stored in a special class which you normally do not get to see:

irb(main):018:0> String.singleton_class
=> #<Class:String>
irb(main):019:0> String.singleton_class.instance_method :z
=> #<UnboundMethod: #<Class:String>#z>
irb(main):020:0> String.method :z
=> #<Method: String.z>

irb(main):021:0> o.singleton_class
=> #<Class:#<Object:0x802a6414>>
irb(main):022:0> o.singleton_class.instance_method :s
=> #<UnboundMethod: #<Class:#<Object:0x802a6414>>#s>
irb(main):023:0> o.method :s
=> #<Method: #<Object:0x802a6414>.s>

The alternative syntax to define singleton methods reflects that.
Instead of def o.s we can do

irb(main):024:0> class <<o; p self; def t; "another singleton method" end end
#<Class:#<Object:0x802a6414>>
=> nil
irb(main):025:0> o.t
=> "another singleton method"

Note the "p" is there just to show it's the same class as was returned
from o.singleton_method.

So even in this case the method definition is stored in a class,
albeit a special class which only has one instance:

irb(main):026:0> o.singleton_class.new
TypeError: can't create instance of singleton class
        from (irb):26:in `new'
        from (irb):26
        from /usr/bin/irb:12:in `<main>'

There is no way I am aware of to make it have more instances:

irb(main):027:0> q = o.dup
=> #<Object:0x8022ef40>
irb(main):028:0> q.singleton_class.equal? o.singleton_class
=> false
irb(main):029:0> q.singleton_class
=> #<Class:#<Object:0x8022ef40>>
irb(main):030:0> o.singleton_class
=> #<Class:#<Object:0x802a6414>>

irb(main):031:0> q = o.clone
=> #<Object:0x802e9db8>
irb(main):032:0> q.singleton_class
=> #<Class:#<Object:0x802e9db8>>
irb(main):033:0> q.singleton_class.equal? o.singleton_class
=> false
irb(main):034:0> ObjectSpace.each_object(o.singleton_class) {|o| p o}
#<Object:0x802a6414>
=> 1

But o and q share singleton methods:

irb(main):035:0> q.s
=> "singleton method on a non class and non module object"
irb(main):036:0> q.t
=> "other singleton method"

And incidentally they share the same definition of those singleton methods

irb(main):037:0> o.method(:s).unbind
=> #<UnboundMethod: #<Class:#<Object:0x802a6414>>#s>
irb(main):038:0> q.method(:s).unbind
=> #<UnboundMethod: #<Class:#<Object:0x802a6414>>#s>
irb(main):039:0> o

I can override one and the other stays intact

irb(main):041:0> def o.s; "overridden" end
=> nil
irb(main):042:0> o.s
=> "overridden"
irb(main):043:0> q.s
=> "singleton method on a non class and non module object"
irb(main):044:0> o.method(:s).unbind
=> #<UnboundMethod: #<Class:#<Object:0x802a6414>>#s>
irb(main):045:0> q.method(:s).unbind
=> #<UnboundMethod: #<Class:#<Object:0x802a6414>>#s>


Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

In This Thread

Prev Next