From: andrea Date: 2012-03-29T23:11:33+09:00 Subject: Re: Why z = Complex(1,2) rather than z = Complex.new(1,2)? --_=__=_XaM3_.1333030284.2A.671410.42.13990.52.42.007.530174812 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I'd add that, while this works, you better have a very good reason for do= ing so - it breaks convention.=0A=C2=A0=0A--=0A=C2=A0=0Ahttp://usingimho.= wordpress.com=0Ahttp://github.com/bolthar=0ADa: "Jan E." lists@ruby-forum= .com=0AA: ruby-talk@ruby-lang.org=0ACc: =0AData: Thu, 29 Mar 2012 23:00:5= 7 +0900=0AOggetto: Re: Why z =3D Complex(1,2) rather than z =3D Complex.n= ew(1,2)?=0A=0A> Hi,=0A> =0A> You *can* define upper-case methods, but whe= n you call them, you always =0A> have to use parenthesis so that Ruby doe= sn't confuse them with =0A> constants:=0A> =0A> ####=0A> def Hallo=0A> = puts 'Hallo Welt!'=0A> end=0A> =0A> Hallo()=0A> ####=0A> =0A> However, th= is violates the naming conventions of Ruby, so you shouldn't =0A> do it. = Why not define a [] method?=0A> =0A> ####=0A> class MyClass=0A> def ini= tialize value=0A> @value =3D value=0A> end=0A> attr_reader :value= =0A> def self.[] value=0A> new value=0A> end=0A> end=0A> =0A> a =3D= MyClass[4]=0A> puts a.value=0A> ####=0A> =0A> -- =0A> Posted via http://= www.ruby-forum.com/.=0A> --_=__=_XaM3_.1333030284.2A.671410.42.13990.52.42.007.530174812 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable =0A
=0A
I'd add that, while this works, you bett= er have a very good reason for doing so - it breaks convention.
 
--
 
http://usingimho.wordpres= s.com
http://github.com/bolthar


=0A
Da: "Jan E." lists@ruby-forum.com
=0A
A: ruby= -talk@ruby-lang.org
=0A
Cc:
=0AData= : Thu, 29 Mar 2012 23:00:57 +0900
=0A
<= span style=3D"font-family:Arial; font-size:11px; color:#5F5F5F;">Oggetto<= /span>: Re: Why z =3D Complex(1,2) rather than z =3D Complex.n= ew(1,2)?
=0A
=0A
> Hi,
>
&g= t; You *can* define upper-case methods, but when you call them, you alway= s
> have to use parenthesis so that Ruby doesn't confuse th= em with
> constants:
>
> ####
> def Hallo
> puts 'Hallo Welt!'
>= end
>
> Hallo()
> ####
>
> However, this violates the naming conventions of Ru= by, so you shouldn't
> do it. Why not define a [] method?
>
> ####
> class MyClass
> def initialize value
> @value =3D value
> end
> attr_reader :value
> def sel= f.[] value
> new value
> end
&g= t; end
>
> a =3D MyClass[4]
> put= s a.value
> ####
>
> --
> Posted via http://www.ruby-forum.com/.
>
= =0A=0A --_=__=_XaM3_.1333030284.2A.671410.42.13990.52.42.007.530174812--