diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-08-13 05:45:20 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-08-13 05:45:20 +0000 |
commit | 65a5162550f58047974793cdc8067a970b2435c0 (patch) | |
tree | 082bb7d5568f3b2e36e3fe166e9f3039394fcf44 /sample/list.rb | |
parent | fcd020c83028f5610d382e85a2df00223e12bd7e (diff) |
1.4.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/list.rb')
-rw-r--r-- | sample/list.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sample/list.rb b/sample/list.rb index 76035e67d6..221f7edb16 100644 --- a/sample/list.rb +++ b/sample/list.rb @@ -1,8 +1,8 @@ # Linked list example class MyElem - # ���֥��������������˼�ưŪ�˸ƤФ���å� + # object initializer called from Class#new def initialize(item) - # @�ѿ��ϥ������ѿ�(������פ�ʤ�) + # @variables are instance variable, no declaration needed @data = item @succ = nil end @@ -15,7 +15,7 @@ class MyElem @succ end - # ��obj.data = val�פȤ����Ȥ��˰��ۤ˸ƤФ���å� + # the method invoked by ``obj.data = val'' def succ=(new) @succ = new end @@ -40,12 +40,12 @@ class MyList end end - # ���֥������Ȥ�ʸ������Ѵ������å� - # ��������������print�Ǥ�ɽ�����Ѥ�� + # the method to convert object into string. + # redefining this will affect print. def to_s str = "<MyList:\n"; for elt in self - # ��str = str + elt.data.to_s + "\n"�פξ�ά�� + # short form of ``str = str + elt.data.to_s + "\n"'' str += elt.data.to_s + "\n" end str += ">" @@ -64,7 +64,7 @@ class Point end end -# ����ѿ���`$'�ǻϤޤ롥 +# global variable name starts with `$'. $list1 = MyList.new $list1.add_to_list(10) $list1.add_to_list(20) @@ -75,6 +75,6 @@ $list2.add_to_list(20) $list2.add_to_list(Point.new(4, 5)) $list2.add_to_list($list1) -# ۣ��Ǥʤ��¤��åɸƤӽФ��γ�̤Ͼ�ά�Ǥ��� +# parenthesises around method arguments can be ommitted unless ambiguous. print "list1:\n", $list1, "\n" print "list2:\n", $list2, "\n" |