RoR_2_Ruby

324 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
324
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

RoR_2_Ruby

  1. 1. Ruby on Rails #2 Ruby helper2424@gmail.com 1
  2. 2. What is Ruby • Programing language • Dynamic • Multi‑paradigm: OOP, functional, imperative, reflection • Influenced by: Perl, Smalltalk, Lisp, C++, Python ... • Created in the mid‑1990s • "I wanted a scripting language that was more Yukihiro Matsumoto (Japan) powerful than Perl, and more object‑oriented than Python. Thats why I decided to design my own language." helper2424@gmail.com 2
  3. 3. Deeper in the Ruby • Latest stable version 1.9.3‑p286 • RoR 3.0 has bugs with Ruby 1.8.7 p248 and p249 • RoR 3.0 has conflicts with 1.9.1 • Use RoR 3.x with Ruby 1.9.>=2 • Ruby License helper2424@gmail.com 4
  4. 4. Philosophy • Everything is object (numbers, primitives, methods and classes too) • Every object has class and superclass • The root of class hierarchy is Object • Ruby has not static methods or variables • All instance variables are private • Interfacejava mechanism through modules • Module (like class, but) has not variables helper2424@gmail.com 5
  5. 5. Hello world #!/usr/bin/ruby #!/usr/bin/ruby # coding: utf‑8# coding: utf‑8 def hello_world();puts "Hello World!" puts "Hello world"; end; hello_world(); #!/usr/bin/ruby # coding: utf‑8 def hello_world puts "Hello world" end hello_world helper2424@gmail.com 3
  6. 6. Ok, now install Ruby • http://en.wikibooks.org/wiki/Ruby_Programmin g/Installing_Ruby • All examples work with Ryby 1.9.3p125 helper2424@gmail.com 7
  7. 7. Little bit of syntax #One line comments =begin multiline comments (=begin and =end in one column) =end Its string and "Its string" and %q!Its string too! a # variable $b # global variable @c # instance variable Constant # but u can change it if bribe conscience helper2424@gmail.com 7
  8. 8. Functions def this_function() #function_body end def this_function #function_body end def ==(variable) #overload operator end helper2424@gmail.com 8
  9. 9. Classes class Your_class @test # by default private def test_method #by default public #code end private #yep, private modificator like in C++ def test_method2 #private #code end public def test_method # public #code end end helper2424@gmail.com 9
  10. 10. Code blocks def test print "<<" yeild "Wolrd" end test do |x| print " Hello #{x} ! >>" end # result << Hello World ! >> helper2424@gmail.com 10
  11. 11. Libraries • All through packages • Self package system (gem) helper2424@gmail.com 11
  12. 12. Some features • Ruby has interactive interpretator irb • Ruby slow with Windows (Ruby isnt optimized for windows, because most core developers use Linux) • Interpretator encoding is utf8 helper2424@gmail.com 9
  13. 13. Links • http://www.ruby‑lang.org/en/ ‑ Ruby official site • http://en.wikibooks.org/wiki/Ruby_Programmin g/Installing_Ruby ‑ install Ruby • http://www.ruby‑doc.org/ ‑ documentation • http://tryruby.org/ ‑ interactive for learning ruby for beginers • http://rubymonk.com/ ‑ use it after truruby (for beginers too) helper2424@gmail.com 10
  14. 14. Literature in RU • Michael Fitzgerald "Learning Ruby": superficial • David Flanagan and Yukihiro Matsumoto "The Ruby Programming Language" : detailed book helper2424@gmail.com 11
  15. 15. Literature in EN • David A. Black "The Well‑Grounded Rubyist" : good book • Dave Thomas, Chad Fowler, Andy Hunt "Programming Ruby 1.9 (3rd edition): The Pragmatic Programmers Guide" : good book too helper2424@gmail.com 11
  16. 16. Additional literature • Russ Olsen "Design Patterns In Ruby" : patterns for rubists • William C. Wake, Kevin Rutherford "Refactoring in Ruby" : all in name • Jay Fields, Shane Harvie, Martin Fowler "Refactoring: Ruby Edition" : Fowlerss "Refactoring" with examples for Ruby helper2424@gmail.com 13

×