Ruby for newbies Lake Ainsworth
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Ruby for newbies Lake Ainsworth

on

  • 598 views

 

Statistics

Views

Total Views
598
Views on SlideShare
597
Embed Views
1

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 1

http://www.hanrss.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ruby for newbies Lake Ainsworth Presentation Transcript

  • 1. Ruby for Newbies Andrew Grimm University of New South Wales
  • 2. What is Ruby?Multi-paradigm language Object-oriented programming Functional programming Procedural programming
  • 3. Just about everything is an Object>> 42.is_a?(Object)=> true>> "hello world".is_a?(Object)=> true>> nil.is_a?(Object)=> true>> Object.is_a?(Object)=> true>> Class.is_a?(Object)=> true
  • 4. Just about all instructions are methodsputs “hello world” is a call to the method `puts`>> private_methods.grep(/puts/)=> ["puts"]
  • 5. Enumerations(1..5).each {|x| puts x}(1..5).map {|x| x * 2}(1..5).find_all {|x| x.odd?}(1..5).sort_by {|x| [x.odd?.to_s, x]}(1..5).group_by {|x| x.odd?}
  • 6. Ruby (kind of) does functional programminggrouping_by = Proc.new {|x| x % 6 }what_to_do = Proc.new {|x| p x}numbers = 1..50def group_by_and_process(numbers, grouping_by, what_to_do) what_to_do.call(numbers.group_by(&grouping_by))end
  • 7. Metaprogrammingplus = :+number_1 = 12number_2 = 30number_1.send(plus, number_2) # => 42
  • 8. You can do just about anythingold_stdout = STDOUTSTDOUT = StringIO.newSTDOUT.puts "this wont be printed"STDOUT = old_stdoutSTDOUT.puts "this will be printed"