SlideShare a Scribd company logo
Learning from
Ruby
Kang-min Liu <gugod@gugod.org>
YAPC::Asia::2009
Gugod->meta
•                              •   http://handlino.com/
    Kang-min Liu
    gugod


•   http://gugod.org


•   http://search.cpan.org/
    ~gugod/


•   http://twitter.com/gugod


•   gugod@gugod.org
Learning from
Ruby
Learning from
Ruby
Ruby is Lovely
(The programming language)
Perl 6 Logo
Language
rubyisms.pm
by Simon Cozens
rubyisms.pm

• Class
• new
• self
• super
• yield
Learning From Ruby (Yapc Asia)
Perl ~~ Ruby
Ruby
self
class Foo
 def bar
   self.baz
 end

 def self.bar
  self.baz
 end
end
class Foo
        def bar
object
          self.baz
        end

       def self.bar
        self.baz
       end
      end
class Foo
         def bar
 object
           self.baz
         end

Class    def self.bar
          self.baz
         end
        end
class Foo
 def bar
   baz
 end

 def self.bar
  baz
 end
end
block syntax
def foo(arg1, arg2)
 yield(a, b)
end



foo(arg1, arg2) do |block_arg1, block_arg2|
 ...
end
co-routine
callback
call me after you
done that.
div(id => "content") do
 h1(id => "title") { "OHAI" }
 p(class => "block") { "Cheeze?" }
end
app do
 alert(42)
end
Good Built-in
Classes
Range
Lazy
irb> 1..2**100
=>
1..1267650600228229401496703205376
irb> (1..2**100).class
=> Range
(1..2**100).each do |i|
 puts 42
 break if i >= 5
end
autobox
no Semicolon
Rubyish.pm
It’s all sugar, honey.
Rubyish.pm

• Kernel, Object, Module, Class
• Array, Hash, String, TrueClass,
  NilClass, Enumerable

• Syntax
 • def, nil, true, false
class Foo {

}
def foo {
  # $self;
}
def foo($arg1, $arg2) {

}
see also:
MooseX::Declare
my $array = Array[0..3];
if ($array->any { $_ > 2 }) {
    ...
}
# Rubyish::Array
$arr = Array[1..10];

# Rubyish::Hash
$hash = Hash{ a => 42, b => "stuff" };

# Rubyish::String
$str = String("FooBar");
ref:
Class::Builtin
boolean

• true – TrueClass
• false - FalseClass
• nli - NilClass
sub true() {
  Rubyish::TrueClass->new
}
ref:
boolean.pm
and Acme::Boolean
Hash is lazy too
fib = Hash.new { |fib, k| fib[k] = fib[k-1] + fib[k-2] }
fib[0] = 0
fib[1] = 1

puts fib[10]
# => 55
Functional
programming
-ish
Memoize

   sub fib {
     my $n = shift;
     return $n if $n < 2;
     fib($n-1) + fib($n-2);
   }
   memoize('fib');
Lazy stuffs

• Scalar::Lazy
• Variable::Lazy
• Scalar::Defer
• Data::Thunk
Lazy stuffs

• Tie::Array::Lazy
• Tie::Array::Lazier
• Hash + Lazy = ?
Hash::Lazy
Hash::Lazy
  my $fib = Hash {
    my ($h, $k)= @_;
    return $h->{$k-1} + $h->{$k-2}
  };
  $fib->{0} = 0;
  $fib->{1} = 1;

  say $fib->{10}; # 55
Hash::Lazy


• export “Hash” as the constructor
• Hash::Lazy::Tie
Learnt
• I hate doing tie
• Spiffy constructors can be good
  read

 • Hash
 • Rubyish.pm: Array, Hash, String
 • Class::Builtin: OO
PerlX::MethodCall
WithBlock
Still more syntax sugar
Schwartzian
Transform
        Ruby

     (0..10)
     .map { |i| i * 13 }
     .map { |i| i % 17 }
     .sort { |a,b| a <=> b }
Schwartzian
Transform
        Perl5

     sort { $a <=> $b }
     map { $_ % 17 }
     map { $_ * 13 }
     (0..10)
Schwartzian
Transform autobox
     Perl5, with

     [0..10]
     ->map(sub { $_ * 13 })
     ->map(sub { $_ % 17 })
     ->sort(sub { $a <=> $b })
Schwartzian
Transform
     Perl5, extended!


       [0..10]->map {
          $_ * 13
       }->map {
          $_ % 17
       }->sort {
          my ($a,$b) = @_;
          $a <=> $b
       };
Schwartzian
Transform
     Perl5, extended!

       [0..10]
       ->map { $_ * 13 }
       ->map { $_ % 17 }
       ->sort { $_[0] <=> $_[1] }
PerlX ::
MethodCallWithBlo
ck
ref

• B::OPCheck
 • lineseq, pushmark, const
• B::Hooks::EndOfScope
• Devel::Declare
ref

• opcode.pl, opcode.h
• B::Concise
• B::Deparse
PerlX
Community
Last month
Sh*t happened
Taiwan
Morakot
Learning From Ruby (Yapc Asia)
☹
Learning From Ruby (Yapc Asia)
Learning From Ruby (Yapc Asia)
$WebSite.com
Learning From Ruby (Yapc Asia)
xdite
☹
DisasterTW.com
DisasterTW.com


• Forum
• Initial Coding: 1 hour*woman.
Learning From Ruby (Yapc Asia)
1 day later
Learning From Ruby (Yapc Asia)
DisasterTW.com

• Web 2.0 / Social-ish
• Multi-Function
• Mash-able
DisasterTW.com




         ✖
• Web 2.0 / Social-ish
• Multi-Function
• Mash-able
DisasterTW.com

• Online ASAP
• Robust (peak: 400k PV/day)
• Well-known
DisasterTW.com

• Rapid Prototyping
• Cloud Computing
• SEO / Social Network Friendly
DisasterTW.com

• Ruby on Rails
• Heroku + Panther CDN
• Good HTML / Plurk button
DisasterTW.com

• 6 heroku instances
• Thousands of tweets about
  #morakot

• Total Cost: ~50 USD
Learning From Ruby (Yapc Asia)
People are
awesome
Tools are
awesome
Problem →
What if it was a
Jifty site?
@obra can haz
dancing
@obra can haz
dancing, naked
DisasterTW.com

• Rapid Prototyping
• Cloud Computing
• SEO / Social Network Friendly
DisasterTW.com

• Jifty
• Cloud Computing
• Good HTML / Plurk button
Heroku for Perl?
∴
Ruby is Lovely
Ruby is a
respectful friend
of Perl
Ruby programmers
are respectful friends
of Perl programmers
Thanks for Listening

More Related Content

KEY
YAPC::Tiny Introduction
PDF
Ruby 程式語言簡介
PDF
Ruby 程式語言入門導覽
PDF
Perl 5.10
KEY
An introduction to Ruby
PDF
Ruby 1.9
ODP
Perl dancer
PDF
Blocks by Lachs Cox
YAPC::Tiny Introduction
Ruby 程式語言簡介
Ruby 程式語言入門導覽
Perl 5.10
An introduction to Ruby
Ruby 1.9
Perl dancer
Blocks by Lachs Cox

What's hot (20)

PDF
Good Evils In Perl
PDF
I, For One, Welcome Our New Perl6 Overlords
PPTX
Joy of Six - Discover the Joy of Perl 6
PDF
Vim Script Programming
PDF
Follow the White Rabbit - Message Queues with PHP
KEY
PHPerのためのPerl入門@ Kansai.pm#12
PDF
Shell Script
PDF
Discovering functional treasure in idiomatic Groovy
KEY
groovy & grails - lecture 3
PDF
Ruby 1.9
KEY
Good Evils In Perl (Yapc Asia)
PDF
Modern Getopt for Command Line Processing in Perl
PDF
Perl 6 by example
PDF
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
PDF
Happy Go Programming
PPT
Working with databases in Perl
PDF
High Performance tDiary
PDF
PL/Perl - New Features in PostgreSQL 9.0
PDF
Rubinius - A Tool of the Future
PPT
Functional Pe(a)rls version 2
Good Evils In Perl
I, For One, Welcome Our New Perl6 Overlords
Joy of Six - Discover the Joy of Perl 6
Vim Script Programming
Follow the White Rabbit - Message Queues with PHP
PHPerのためのPerl入門@ Kansai.pm#12
Shell Script
Discovering functional treasure in idiomatic Groovy
groovy & grails - lecture 3
Ruby 1.9
Good Evils In Perl (Yapc Asia)
Modern Getopt for Command Line Processing in Perl
Perl 6 by example
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
Happy Go Programming
Working with databases in Perl
High Performance tDiary
PL/Perl - New Features in PostgreSQL 9.0
Rubinius - A Tool of the Future
Functional Pe(a)rls version 2
Ad

Viewers also liked (7)

PPT
Ppoint blog
PDF
PDF
SQL Server Managing Test Data & Stress Testing January 2011
KEY
Perlbrew
PDF
Same but Different
PDF
perlbrew yapcasia 2010
PDF
Elasticsearch 實戰介紹
Ppoint blog
SQL Server Managing Test Data & Stress Testing January 2011
Perlbrew
Same but Different
perlbrew yapcasia 2010
Elasticsearch 實戰介紹
Ad

Similar to Learning From Ruby (Yapc Asia) (20)

PDF
Hacking with ruby2ruby
PDF
Practical Testing of Ruby Core
PDF
The $path to knowledge: What little it take to unit-test Perl.
PDF
Ruby presentasjon på NTNU 22 april 2009
PDF
Ruby presentasjon på NTNU 22 april 2009
PDF
Ruby presentasjon på NTNU 22 april 2009
PDF
Ruby 2.0
PPTX
Perl basics for Pentesters
PDF
Ruby is an Acceptable Lisp
PDF
Static Optimization of PHP bytecode (PHPSC 2017)
PDF
Ruby 入門 第一次就上手
KEY
Rails for PHP Developers
ODP
Whatsnew in-perl
ODP
A Toda Maquina Con Ruby on Rails
PDF
PHP Performance Trivia
ODP
Perl Moderno
PDF
Hiveminder - Everything but the Secret Sauce
PPT
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
PPTX
Modern Perl
PDF
Vim Hacks
Hacking with ruby2ruby
Practical Testing of Ruby Core
The $path to knowledge: What little it take to unit-test Perl.
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
Ruby 2.0
Perl basics for Pentesters
Ruby is an Acceptable Lisp
Static Optimization of PHP bytecode (PHPSC 2017)
Ruby 入門 第一次就上手
Rails for PHP Developers
Whatsnew in-perl
A Toda Maquina Con Ruby on Rails
PHP Performance Trivia
Perl Moderno
Hiveminder - Everything but the Secret Sauce
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Modern Perl
Vim Hacks

More from Kang-min Liu (11)

PDF
o̍h Tai-gi
PDF
The architecture of search engines in Booking.com
PDF
Integration Test With Cucumber And Webrat
PDF
Javascript Tutorial
PDF
Javascript Basic
PDF
Handlino - RandomLife
PDF
Jformino
PDF
Test Continuous
PDF
網頁程式還可以怎麼設計
PDF
OSDC.tw 2008 Lightening Talk
PDF
Happy Designer 20080329
o̍h Tai-gi
The architecture of search engines in Booking.com
Integration Test With Cucumber And Webrat
Javascript Tutorial
Javascript Basic
Handlino - RandomLife
Jformino
Test Continuous
網頁程式還可以怎麼設計
OSDC.tw 2008 Lightening Talk
Happy Designer 20080329

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
KodekX | Application Modernization Development
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Monthly Chronicles - July 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
KodekX | Application Modernization Development
The AUB Centre for AI in Media Proposal.docx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding

Learning From Ruby (Yapc Asia)

Editor's Notes

  • #5: Before we learn what we&amp;#x2019;re learning, let&amp;#x2019;s learn it first.
  • #7: If you google &amp;#x201C;Perl 6 Logo&amp;#x201D;, you get this picture. Ruby is so awesome that people once think that we don&amp;#x2019;t need Perl 6 anymore.
  • #8: I want to start by telling you my learnings from the language aspect
  • #9: by Simon Cozens.
  • #11: After seeing rubyisms, I asked my self a question:
  • #12: Can Perl programs have the same look and feel of Ruby programs?
  • #13: There are several good parts of Ruby that I like...
  • #14: The self keyword &amp;#x2013; It doesn&amp;#x2019;t always mean &amp;#x201C;the current object&amp;#x201D; like in java.
  • #17: Those baz in there refers to different baz method.
  • #19: The &amp;#x2018;yield&amp;#x2019; there means to invoke call the given block as a method.
  • #23: One good use: Markaby
  • #24: Another one Hot cocoa.
  • #30: Ruby primitive data types are all Objects
  • #31: It requires the statements to be written nicely, but it&amp;#x2019;s nice not having to write semicolons sometimes.
  • #34: Now you can define a class with keyword &amp;#x201C;class&amp;#x201D;
  • #35: and define instance methods with keyword &amp;#x201C;def&amp;#x201D;
  • #36: plus function prototype
  • #37: See also that module
  • #38: Export &amp;#x201C;Array&amp;#x201D; method as the constructor of Rubyish::Array.
  • #41: boolean keywords returns the singleton object of their classes
  • #44: Ruby hash has a lovely way to lazily initialize its content.
  • #47: We have Memoize instead of being Lazy. But it doesn&amp;#x2019;t read nicely. And it doesn&amp;#x2019;t happen automagically.
  • #51: You might notice that the &amp;#x201C;Hash&amp;#x201D; returns a hash ref but not a hash. This is required because the it&amp;#x2019;s a reference to a tied hash. So the magic under the table, is to use tie.
  • #63: Let&amp;#x2019;s write more crazy stuffs for this namespace.
  • #79: Hey! It&amp;#x2019;s a Web-two-point-o-ey resource allocation exchange website!
  • #81: Volunteer added good styles
  • #82: Being a website that helps people in such a tragedy, the website should...
  • #83: The whole points for such website
  • #87: Now it&amp;#x2019;s over and the website basically shutdown... I looked back and thought..
  • #90: They see a problem/requirement and they uses the technologies they familiar with.
  • #96: Heroku is so convenient and cheap for RoR deployment. This makes me, as a Perl programmer for year, really jealous.
  • #97: So by the end of this talk, I conclude..