Intro to Ruby (and RSpec)

1,585 views
1,444 views

Published on

An introduction to the Ruby language and RSpec

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,585
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Intro to Ruby (and RSpec)

    1. 1. THE RUBY LANGUAGE
    2. 2. THE RUBY LANGUAGE• Originally by Yukihiro "Matz" Matsumoto• “Ruby is designed for programmer productivity and fun, following the principles of good user interface design. He stresses that systems design needs to emphasize human, rather than computer, needs.” http://en.wikipedia.org/wiki/Ruby_(programming_language)#History• Ruby 1.0 was released in 1996.
    3. 3. RUBY LANGUAGE OVERVIEW• Dynamically typed• Interpreted• Can be modified at runtime• Object oriented• Blocks & lambdas• Nice support for Regular Expressions
    4. 4. RUBY VERSIONSruby -v•1.8.6 – Still around but mostly supplanted by 1.8.7•1.8.7 – some 1.9 features, compatible w/ 1.8.6•1.9.2 – latest version, many VMs, Rails 2.3+
    5. 5. RUBY VMS• MRI (Matzs Ruby Interpreter) the original Ruby, default for 1.8• YARV (yet another Ruby VM) faster than MRI, default for 1.9• JRuby (Java)• Rubinius (pure ruby)• IronRuby (.NET)• MacRuby, HotCocoa• HotRuby/RubyJS (Flash/Javascript)
    6. 6. LETS GET STARTED• IRB: InteractiveRuBy>> 4>> 4 + 4
    7. 7. EVERYTHING IS AN OBJECT“test”.upcase“test”.class“test”.methods
    8. 8. EVERYTHING EVALUATES TO SOMETHING2+2(2+2).zero?
    9. 9. METHODS ARE MESSAGESthing.do(4)thing.do 4thing.send “do”, 4
    10. 10. OPERATORS ARE METHODSthing.do 4 3+2thing.do(4) 3.+(2)thing.send “do”, 4 3.send "+", 2
    11. 11. DEFINING CLASSES• Let’s write some code!
    12. 12. INTRODUCTION TO RSPEC• Describe the feature• Verify expectation
    13. 13. RSPEC SYNTAXdescribe Something doend
    14. 14. RSPEC SYNTAXdescribe Something do it "should do whatever it should do"end
    15. 15. RSPEC SYNTAXdescribe Something do it "should do whatever it should do" do endend
    16. 16. RSPEC SYNTAXdescribe Something do it "should do whatever it should do" do s = Something.new endend
    17. 17. RSPEC SYNTAXdescribe Something do it "should do whatever it should do" do s = Something.new s.do_whatever(3, 2, 1) endend
    18. 18. RSPEC SYNTAXdescribe Something do it "should do whatever it should do" do s = Something.new s.do_whatever(3, 2, 1).should == "blast off!" endend
    19. 19. RSPEC SYNTAXdescribe Something do it "should do whatever it should do" do s = Something.new s.do_whatever(3, 2, 1).should == "blast off!" endend
    20. 20. • Lets try it!

    ×