Sun Microsystems, Inc. Agenda • ������������������������ • �������������������������������� • ����������������� • ������������������� • ���������������� • �������������������� • ����������� • ���������������� • ������������!���"���!�����!�������� � Who am I • $�������%��!���&����� • '����������!����!�������()*+����, • -���������������.����������������)��� • /���"�������������!������ • 0����������������1.���������������� • ��������������������2�������� > $3�$++3�$43�����3�������3�������3�'���3������� > ��!��--�����.-3��5&53��� # Page 1
Sun Microsystems, Inc. What Is Ruby • �������"�����3������%%��������� > 5���������� > %����������3������������$ > 7������������������3�������������3���������3�8���9 > ������������������3����������������3����������3�8����9 • $�������)::#����;��������8.��<9�.�������� > 8.��������������������������������%%������������9 • 1��������!�����������3������������������� • �����)=>=2�����������3�)=:���������!������������ ��������=* 6 Ruby Quick Tour: Pure OO • -!���������������%�@��� > $�����=���(6, AB�������������$����� > 8���9=������� AB�# > )=��C� ������AB�8)9 • 0���%�@����������������������$������ > )=����� AB�/�2��� • ������"5���������� • %�@�������������������������������� ? Ruby Quick Tour: Basics • '������� > Fixnum: 1 > Float: 1.0 > Bignum: 12345678987654321 > String: “one” 'one' %Q[one] %q[one] ... > Multiline string (“here doc”): x = <<EOS extend across two lines EOS > Symbol: :one, %s[one] > Regexp: /^foo\w+.*bar$/, %r[^foo$] > Array: [1, “ein”, :ichi] > Hash: {:one => 1, :two => 2} D Page 2
Sun Microsystems, Inc. Ruby Quick Tour: Basics • String substitution > a = “foo” > b = “bar#{a}baz” => “barfoobaz” • Operator overloading > def +(arg); ... • Attributes > class Foo attr_accessor :a end x = Foo.new x.a = “hello” puts x.a => “hello” E Ruby Quick Tour: Duck Typing • �������������� • 85��������������������������������F�����������������===9 def make_it_waddle(waddler) waddler.waddle end make_it_waddle(Duck.new) make_it_waddle(Penguin.new) make_it_waddle(Octopus.new) • ���������������������������� > G���������������������!�������� > Ruby Quick Tour: A Simple Class ����� � ����� ������������������������������������ �� ��� � ���������� ��������� ���������������������� �� ��� �� ��� � ����� ��������������������������������������� ���������������� �� �������� � � �� ��� ��� �������������������������� �������� ����� ������ !""#�� ����������� : Page 3
Sun Microsystems, Inc. Ruby Quick Tour: Blocks ������$������%��������&'���(�(�������( ) � *� � *� � +������&,������,������- � ������&������'-�' ) � *� � *� � +������ �� �,������, �������- � ������&������'- ��� �������(������������������.� ��� � ��� �� ����� �-�����- ��� ��� � ���� �/����.� ������.������-�����-� ��� )* Ruby Quick Tour: Modules ��!�������������$�������� ����� � ���������� ����0�������������1�(������������������(� �������(�� ���������� �� ����(�$�������������������(�������������� �� ��� � ���� �������������������������������� �� ��� ��� ������� ���������� ���� ������������&,����,������������2� !"" ' ����������&,�*��,��������3�2�������' �������4 )) JRuby • ��!��������������������������������� • ������������**�3������������3������������������ • 0������������������������������������������!������ • &���!�����������3������������������ • ������**E��)=*��������3����������������������� • �����**E��)=)��������3��������������������� )� Page 4
Recommend
More recommend