From: matz@ruby-lang.org (Yukihiro Matsumoto)
To: ruby-core@ruby-lang.org
Subject: Re: subclassing Structs
Date: Fri, 15 Aug 2003 02:04:23 +0900 [thread overview]
Message-ID: <1060880652.622088.27404.nullmailer@picachu.netlab.jp> (raw)
In-Reply-To: Eugene Scripnik's message of "Thu, 14 Aug 2003 18:57:59 +0900" <3F3B5C35.1070309@itgrp.net>
Hi,
In message "Re: subclassing Structs"
on 03/08/14, Eugene Scripnik <Eugene.Scripnik@itgrp.net> writes:
|My example didn't show that but I wanted to create struct-class with
|dynamic attributes and additional constructors.
|
|class SubStruct < Struct
| def new2
| new( 'attr1_value', 'attr2_value' )
| end
|end
|
|new2 - instance method of SubStruct (Struct) and I thought it has to be
|class method of SubStruct.new( ... ) class.
Unlike other classes, Struct.new returns its subclass, not instance.
This is very exceptional behavior.
new2 is an instance method of SubStruct.
class SubStruct < Struct
def new2
new(:foo, :bar)
end
end
C = MyStruct.new(:foo)
p C.ancestors # => [C, MyStruct, Struct, Enumerable, Object, Kernel]
p C.new.new2 # "new2" here. but not "new"
matz.
next prev parent reply other threads:[~2003-08-14 16:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-13 15:16 subclassing Structs Eugene Scripnik
2003-08-13 16:53 ` Yukihiro Matsumoto
2003-08-14 9:57 ` Eugene Scripnik
2003-08-14 17:04 ` Yukihiro Matsumoto [this message]
2003-08-15 10:35 ` Eugene Scripnik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1060880652.622088.27404.nullmailer@picachu.netlab.jp \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).