[#396148] Facebook Group — Moses Aronov <mosesaro@...>

There is a facebook group that was recently created so we could all communicate with other fellow developers

13 messages 2012/06/05
[#396178] Re: Facebook Group — Chad Perrin <code@...> 2012/06/06

On Wed, Jun 06, 2012 at 01:55:48AM +0900, Moses Aronov wrote:

[#396186] Inexplicable Argument Error — Doug Jolley <lists@...>

I am encountering a very strange argument error. I simplified my code

12 messages 2012/06/06

[#396229] Thread#kill is not rescued by "rescue Exception" — Iñaki Baz Castillo <ibc@...>

Hi, let me show this easy code:

13 messages 2012/06/07

[#396333] Is "a,b=c,d" atomic? or do I need a Mutex? — Iñaki Baz Castillo <ibc@...>

Hi, I have two methods that could be called by different threads and

10 messages 2012/06/10

[#396357] ffi - Popping image on top of the screen — "Damián M. González" <lists@...>

Ey guys, how are you? I`m developing an application in Ruby, using

12 messages 2012/06/11

[#396373] Why should I learn ruby? — Kasper Steensig <lists@...>

I have wondered whether I should learn ruby or python hence they are

16 messages 2012/06/11

[#396503] Syntax Highlighter — Intransition <transfire@...>

Would you agree that Ruby shouldn't lack for a syntax highlighting library

18 messages 2012/06/14

[#396589] Unsubcripe — Suresh Rajkumar <sureshrajchennai@...>

Unsubcipe my mail address from the group.

13 messages 2012/06/18

[#396615] Symbols and Strings... — Hal Fulton <rubyhacker@...>

Hello, all...

29 messages 2012/06/18
[#396620] Re: Symbols and Strings... — Eric Hodel <drbrain@...7.net> 2012/06/18

On Jun 18, 2012, at 15:09, Hal Fulton wrote:

[#396641] Re: Symbols and Strings... — Robert Klemme <shortcutter@...> 2012/06/19

On Tue, Jun 19, 2012 at 12:31 AM, Eric Hodel <drbrain@segment7.net> wrote:

[#396643] Re: Symbols and Strings... — Hal Fulton <rubyhacker@...> 2012/06/19

Personally, I don't have a problem with "reducing the contract"

[#396646] Re: Symbols and Strings... — Robert Klemme <shortcutter@...> 2012/06/19

On Tue, Jun 19, 2012 at 5:17 PM, Hal Fulton <rubyhacker@gmail.com> wrote:

[#396659] Re: Symbols and Strings... — Hal Fulton <rubyhacker@...> 2012/06/19

> > Freezing an object also reduces its contract.

[#396678] Re: Symbols and Strings... — Robert Klemme <shortcutter@...> 2012/06/20

On Tue, Jun 19, 2012 at 10:12 PM, Hal Fulton <rubyhacker@gmail.com> wrote:

[#396701] Re: Symbols and Strings... — Henry Maddocks <hmaddocks@...> 2012/06/20

[#396702] Re: Symbols and Strings... — Bartosz Dziewoński <matma.rex@...> 2012/06/20

2012/6/20 Henry Maddocks <hmaddocks@me.com>:

[#396703] Re: Symbols and Strings... — Henry Maddocks <hmaddocks@...> 2012/06/20

[#396710] Re: Symbols and Strings... — Jeremy Bopp <jeremy@...> 2012/06/20

On 06/20/2012 03:58 PM, Henry Maddocks wrote:

[#396627] Does ERB have recursive template support? — Todd Wei <lists@...>

I want to use ERB template library to do some code generation. It

10 messages 2012/06/19

[#396649] Looking for a better way to add a method to a core class than monkey patching — Iain Barnett <iainspeed@...>

Hi all,

17 messages 2012/06/19
[#396670] Re: Looking for a better way to add a method to a core class than monkey patching — Avdi Grimm <groups@...> 2012/06/20

Please do not monkey patch core libraries in gems, unless the *purpose* of

[#396685] Benchmark obsession? — "Jan E." <lists@...>

Hi,

23 messages 2012/06/20
[#396709] Re: Benchmark obsession? — Ryan Davis <ryand-ruby@...> 2012/06/20

[#396815] Array#sample is Set#sample and not Array#sample ! — Michel Demazure <lists@...>

Arrays are ordered, sets are not. Sampling an array should give random

11 messages 2012/06/25

[#396877] CSV.open problem, help please — Kaye Ng <lists@...>

This code doesn't seem to work

21 messages 2012/06/27

[#396896] Copying text from MS Word and wrapping in HTML - help please — Adam Holloway <lists@...>

Hi,

11 messages 2012/06/27

[#396966] Interactions between 'new' and 'initialize' ? — Cees Zeelenberg <lists@...>

In JRuby, I am extending an existing Java Class with a Ruby initialising

9 messages 2012/06/28

[#396975] stack level too deep for quicksort code — bei zhao <lists@...>

Hi, below is my quicksort implementation in ruby(using the first element

12 messages 2012/06/28

[#396996] Accessor Methods with a Twist — Doug Jolley <lists@...>

I am surprised that the code shown below returns, 'Doug'. I would

15 messages 2012/06/29

[#397001] ruby performance — anaray anaray <lists@...>

Hi,

33 messages 2012/06/29
[#397007] Re: ruby performance — Bartosz Dziewoński <matma.rex@...> 2012/06/29

The MRI is, unfortunately, slow as balls, and there's not much you can

[#397008] Re: ruby performance — Hans Mackowiak <lists@...> 2012/06/29

Bartosz Dziewo=C5=84ski wrote in post #1066673:

[#397010] Re: ruby performance — Bartosz Dziewoński <matma.rex@...> 2012/06/29

2012/6/29 Hans Mackowiak <lists@ruby-forum.com>:

[#397011] Re: ruby performance — Bartosz Dziewoński <matma.rex@...> 2012/06/29

2012/6/29 Hans Mackowiak <lists@ruby-forum.com>:

[#397047] Re: ruby performance — "Andreas S." <lists@...> 2012/07/01

Bartosz Dziewo=C5=84ski wrote in post #1066681:

[#397048] Re: ruby performance — Bartosz Dziewoński <matma.rex@...> 2012/07/01

2012/7/1 Andreas S. <lists@ruby-forum.com>:

[#397068] Re: ruby performance — Robert Klemme <shortcutter@...> 2012/07/02

On Sun, Jul 1, 2012 at 1:42 PM, Bartosz Dziewo=C5=84ski <matma.rex@gmail.co=

[#397086] Re: ruby performance — Dan Connelly <lists@...> 2012/07/02

Here's my contribution:

Re: Interactions between 'new' and 'initialize' ?

From: Robert Klemme <shortcutter@...>
Date: 2012-06-29 12:15:40 UTC
List: ruby-talk #396990
On Thu, Jun 28, 2012 at 5:30 PM, Cees Zeelenberg <lists@ruby-forum.com> wro=
te:
> In JRuby, I am extending an existing Java Class with a Ruby initialising
> block by redefining the 'new' class method.

That does not sound like a good idea.  Class#new should only be
overridden if you need to adjust the initialization process.  What are
you trying to achieve with that?

> This works fine except for new classes which inherit from the original
> class and have a different number of arguments.
> These classes generate a 'wrong number of arguments' error.
> The behavior seems not specific for Java Classes and is actually the
> same for Ruby and JRuby.
> The following example illustrates it, the first version works as
> expected

My example

irb(main):001:0> class A;end
=3D> nil
irb(main):002:0> A.method :new
=3D> #<Method: Class#new>
irb(main):003:0> class B<A;end
=3D> nil
irb(main):004:0> B.method :new
=3D> #<Method: Class#new>
irb(main):005:0> def A.new(x) printf "This won't work, but anyway %p\n", x =
end
=3D> nil
irb(main):006:0> A.method :new
=3D> #<Method: A.new>
irb(main):007:0> B.method :new
=3D> #<Method: B(A).new>
irb(main):008:0> A.new 1
This won't work, but anyway 1
=3D> nil
irb(main):009:0> B.new 2
This won't work, but anyway 2
=3D> nil
irb(main):010:0> irb(main):001:0> class A;end
=3D> #<Method: Class#new>
irb(main):003:0> class B<A;end
=3D> nil
irb(main):004:0> B.method :new
=3D> #<Method: Class#new>
irb(main):005:0> def A.new(x) printf "This won't work, but anyway %p\n", x =
end
=3D> nil
irb(main):006:0> A.method :new
=3D> #<Method: A.new>
irb(main):007:0> B.method :new
=3D> #<Method: B(A).new>
irb(main):008:0> A.new 1
This won't work, but anyway 1
=3D> nil
irb(main):009:0> B.new 2
This won't work, but anyway 2
=3D> nil

> =A0The next example adds a redefinition of Parent.new; Parent goes on to
> work as expected, but Child fails:

Method Class#new must always have signature (*a, &b) because otherwise
it cannot properly forward arguments to #initialize.  As you can see
this is the case for Class#new already:

irb(main):021:0> Class.method(:new).arity
=3D> -1

It has to be that way because #initialize of sub classes actually
defines the signature of the constructor.  Method Class#new basically
does something like this:

irb(main):001:0> class A
irb(main):002:1> def initialize(x) @x=3Dx end
irb(main):003:1> def self.new(*a,&b)
irb(main):004:2> puts "before"
irb(main):005:2> x =3D allocate
irb(main):006:2> printf "allocated %p\n", x
irb(main):007:2> x.send(:initialize, *a, &b)
irb(main):008:2> printf "initialized %p\n", x
irb(main):009:2> x
irb(main):010:2> end
irb(main):011:1> end
=3D> nil
irb(main):012:0> e =3D A.new 123
before
allocated #<A:0x80319e78>
initialized #<A:0x80319e78 @x=3D123>
=3D> #<A:0x80319e78 @x=3D123>

There is only reason if you want to change allocation of instances of
a class (e.g. by taking them from a pool of preallocated instances or
such).  This is rarely the case.

> Is this behavior intentional or a bug? At least it is consistent =A0(Ruby
> 1.8.7, 1.9.1 JRuby 1.6.7)

I think it is intentional and consistent because if you introduce
specific storage characteristics for a class you'll likely want all
subclasses to share it.  The same happens with singleton methods of
class instances generally:

irb(main):001:0> class A;end
=3D> nil
irb(main):002:0> class B<A;end
=3D> nil
irb(main):003:0> A.methods.grep /foo/
=3D> []
irb(main):004:0> B.methods.grep /foo/
=3D> []
irb(main):005:0> def A.foo() puts 123 end
=3D> nil
irb(main):006:0> A.foo
123
=3D> nil
irb(main):007:0> A.methods.grep /foo/
=3D> [:foo]
irb(main):008:0> B.methods.grep /foo/
=3D> [:foo]
irb(main):009:0> B.foo
123
=3D> nil

That way properties you define on a class are available for subclasses as w=
ell.

irb(main):010:0> class <<A; attr_accessor :bar end
=3D> nil
irb(main):011:0> A.bar=3D9
=3D> 9
irb(main):012:0> B.bar
=3D> nil
irb(main):013:0> B.bar=3D123
=3D> 123
irb(main):014:0> B.bar
=3D> 123

> I have tried using alias instead of super and changing the order of
> redefining new and defining initialize. I also tried using class_eval
> and taking the Person.new definition out of the original class
> definition. All to no avail.
> Any help would be appreciated.

Please first explain what your goal is.

Kind regards

robert

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

In This Thread