MMBJ Shanzhai Culture

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    MMBJ Shanzhai Culture - Presentation Transcript

    1. R uby Talk – An Introduction to Premshree Pillai [email_address]
    2. S cope of Talk
      • What this talk is and what it isn’t
      • Me, myself
      • What is?
      • Why use?
      • How to? (a quick run through the syntax)
      • Quick comparisons (with Perl and Python)
      • Resources
    3. P urpose
      • What this talk is?
      • Get you interested
      • Get you started with Ruby
      • What it isn’t?
      • Not a tutorial
    4. W ho am I?
      • (or why should you listen to me)
      • 21/male/single :)
      • Technology consultant
      • Freelance writer since 2001
      • Perl/Python/Ruby/REBOL hacker
    5. H istory (Ruby’s, not mine)
      • Created (in Japan) by Yukihiro Matsumoto, popularly called Matz
      • Named as “Ruby” to reflect its Perl hertitage
      • Released to the public in 1995
      • Licensed under GPL or Ruby terms
    6. W hat the heck is Ruby?
      • An object-oriented “scripting” language
      • As powerful as Perl; simpler, better OO
      • The simplicity of Python
      • Follows the principle of “Least Surprise” – What You Expect Is What You Get
    7. W here can you use Ruby?
      • System (n/w, RegExps)
      • Web programming (using CGI)
        • Agents, crawlers
      • DB programming (using DBI)
      • GUI (Tk, RubyMagick)
    8. G eneral Features
      • High level language
      • True OO (everything’s an object!)
      • Interpreted
      • Portable
      • Low learning curve
      • A quick scan thro’ the syntax
    9. R unning Ruby
      • From the command line:
      • ruby file.rb
      • Windows binary comes bundled with Scintilla
    10. B asic stuff
      • print 'Hello, world!'
      • p 'Hello, world!' # prints with newline
      • my_var = gets # get input
    11. O perators
      • + (addition)
      • - (subtraction/negation)
      • * (multiplication)
      • / (division)
      • % (modulus)
      • ** (exponentiation)
    12. O perators (contd.)
      • ==
      • <=> (returns -1, 0 or 1)
      • <, <=, >=, >
      • =~ (matching)
      • eql? (test of equality of type and values)
    13. O perators (contd.)
      • ++ and -- are not reserved operators
      • Use += and +-
    14. L ogical Operators
      • and
      • or
      • not
    15. T yping
      • Dynamic typed
        • Type checking at run-time
      • Strong typed
    16. B asic Data Types
      • Integers and floats
      • Strings
      • Ranges
      • Arrays
      • Hashes
    17. S trings
      • my_str = 'whatever'
      • my_str = &quot;blah, blah&quot;
      • my_str.split(&quot;,&quot;)[0].split(&quot;&quot;)[2] * 3
    18. R anges
      • Inclusive range
      • my_range = 1 .. 3
      • my_range = 'abc' .. 'abf'
      • Non-inclusive range
      • my_range = 1 … 5
      • my_range = 'abc' … 'abf'
    19. A rrays
      • my_array = [1, 2, 3]
      • Common methods:
      • my_array.length
      • my_array << 4
      • my_array[0], etc.
    20. H ashes
      • my_hash = {
      • 'desc' => {'color' => 'blue',},
      • 1 => [1, 2, 3]
      • }
      • print my_hash['desc']['color']
      • will return
      • blue
    21. H ashes (contd.)
      • Common methods:
      • my_hash.keys
      • my_hash.values
    22. D ata Type Conversion
      • Converting to an Array:
      • var_data_type .to_a
      • Converting to an String:
      • var_data_type .to_s
      • More (guess!):
      • var_data_type .to_i
      • var_data_type .to_f
    23. E verything's an Object
      • Methods can be applied to data directly – not just on variables holding data
      • Example:
      • 5.to_s will return &quot;5&quot;
    24. C ode Blocks
      • Code blocks may use braces ( { } ) or do/end
    25. C ode Blocks (contd.)
      • Example
      • def my_print(what)
      • print what
      • end
      • You cannot use braces for function blocks
    26. I f Statement
      • if expression
      • code block
      • elsif ( expression )
      • code block
      • else
      • code block
      • end
    27. W hile Statement
      • while expression
      • code block
      • end
      • Example:
      • count = 1
      • while count < 10
      • print count
      • count += 1
      • end
    28. F or Loop
      • for variable_name in range
      • code block
      • end
      • Example:
      • for count in 0..2
      • print count
      • end
    29. I terators
      • array_or_range = value
      • array_or_range.each { |x|
      • print x
      • }
      • Example:
      • my_range = 1..5
      • my_range.each { |x|
      • print x
      • }
    30. F unctions
      • Functions begin with the keyword def
      • def function_name ( [args] )
      • code block
      • end
      • Example:
      • def print_name(name='Ruby')
      • print name
      • end
    31. O O Ruby
      • Classes are containers for static data members and functions
      • Declared using the class keyword. All class names should begin with a capital letter
      • Constructor declared using the initialize keyword
      • Class variables precede with an “ @ ”
      • Objects created using the new method
    32. E xample class
      • class My_class
      • def initialize(arg1, arg2)
      • @arg1 = arg1
      • @arg2 = arg1
      • end
      • def print_arg1()
      • print @arg1
      • end
      • def print_foo()
      • print &quot; I Love Ruby! &quot;
      • end
      • private
      • def print_arg2()
      • print @arg2
      • end
      • end
      • my_object = My_class.new(2, 3)
      • my_object.print_arg1
      • my_object.print_arg2 # will cause an exception
    33. I nheritance
      • class Derived_class < My_class
      • def initialize()
      • @arg = &quot;I Love Ruby!&quot;
      • end
      • def print_arg()
      • print @arg
      • end
      • end
      • my_object = Derived_class.new
      • my_object.print_foo
    34. N otes on OO Ruby
      • Access specifiers: public , protected , private
      • Multiple inheritance not possible
    35. R uby modules
      • require 'net/http'
      superclass subclass
    36. A dvanced topics
      • Regular expressions
      • Network programming
      • MT programming
      • GUI programming (using Tk)
      • Web programming
    37. N ow what?
      • What you can do now?
      • Get your hands dirty with Ruby
      • Write simple Ruby programs
      • What you have to do?
      • Explore Ruby modules
      • Find a problem, and Ruby it!
    38. P erl compared to Ruby
      • Complicated OO
      • Cryptic code
      • (Ruby is often called “A Better Perl”)
      • PS: Don’t kill me!
    39. P ython compared to Ruby
      • Incomplete OO
      • Instance variables require self. var
      • No class method
      • No true GC (uses ref counting)
      • Not suitable for one-liners
      • PS: Don’t kill me!
    40. R esources
      • Ruby Home Page
      • http://www.ruby-lang.org/en/
      • Programming Ruby
      • http://www.rubycentral.com/book/
      • RubyGarden
      • http:// www.rubygarden.org /ruby
      • Ruby Application Archive (RAA)
      • http://raa.ruby-lang.org/
    41. R esources (contd.)
      • RubyForge
      • http://rubyforge.org/
      • ruby-talk
      • http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml
      • If God did OOP, he’d probably do it in Python; He’s now considering switching to Ruby!
      • Thank you!
      • Questions?

    + MobileMonday BeijingMobileMonday Beijing, 6 months ago

    custom

    642 views, 1 favs, 4 embeds more stats

    Insights about the Shanzhai culture

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 642
      • 583 on SlideShare
      • 59 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 23
    Most viewed embeds
    • 32 views on http://www.mobinode.com
    • 24 views on http://www.mobilemondaybeijing.com
    • 2 views on http://chinaopps.com
    • 1 views on http://66.163.168.225

    more

    All embeds
    • 32 views on http://www.mobinode.com
    • 24 views on http://www.mobilemondaybeijing.com
    • 2 views on http://chinaopps.com
    • 1 views on http://66.163.168.225

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories