Ruby 1.9.3 Basic Introduction

404 views
328 views

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
404
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ruby 1.9.3 Basic Introduction

  1. 1. Ruby Programmer’s Best Friend D. Prabu Senior Technical Consultant, Spritle Software PVT LTD, Chennai.
  2. 2. History 01 0 2 03 Yukihiro “Matz” Matsumoto February 24, 1993 Matz wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why he decided to design his own language. Perl Java Python Ruby PHP 1987 1991 1993 1995
  3. 3. Photo
  4. 4. Scripting Language A high-level programming language that is interpreted by another program at runtime rather than compiled by the computer's processor as other programming languages (such as C and C++) are. Scripting languages, which can be embedded within HTML, commonly are used to add functionality to a Web page. JavaScript, ASP, JSP, PHP, Perl, Tcl and Python are examples of scripting languages.
  5. 5. Code Sample 5.times { print “Ruby! " }
  6. 6. Code Sample 5.times { print “Ruby! " } Ruby! Ruby! Ruby! Ruby! Ruby!
  7. 7. Conventions Varialbes Class Variable name_of_the_product @@current_client_id Class Name Constants TeamParty PI Symbols :list_Of_items Instance Variables @current_client
  8. 8. Variables Below given are examples of valid variable names orange total_price orange_ _orange buyGift doing747 geting_747 iam23yrsold Below are given examples of invalid variable names 34signals Mango total cost
  9. 9. Everything is an object 1.class # => Fixnum 'a'.class # => String :a.class # => Symbol class Record end Record.class # => Class Record.new.class # => Record
  10. 10. Method, Class and Invocation def do_work(task_ref) task_ref.assigned_work end Class Task def assigned_work puts “Completed successfully.” end end do_work(Task.new) Method Class Invocation
  11. 11. String and Variables variable_name = ‘Nice Infrastructure' # => " Nice Infrastructure " “Good, #{variable_name}" # => “Good, Nice Infrastructure" ‘Good, #{variable_name}' # => "Good, #{variable_name}“
  12. 12. String Functions
  13. 13. Arrays Array.new # => [] Array.new(3) # => [nil, nil, nil] [] # => [] a = [1,2,3] # => [1, 2, 3] a[0] = 'one' # => "one" a # => ["one", 2, 3] a[-1] # => 3 a[1..2] # => [2, 3]
  14. 14. Hashes Hash.new # => {} {} # => {} h = {1 => "one", 2 => "two"} h[1] # => "one“ h["1"] # => nil h[:one] = “course" h[:one] # => "course" h.keys # => [1, 2, :one] h.values # => ["one", "two", "course"]
  15. 15. Loops for count in 1..10 i = 1 print count, " Hellon“ count = 10 end until i > count do print i, " Hellon" (1..10).each do |count| i+=1 print count, " Hellon" end end i = 1 5.times { puts “hi” } count = 10 while i <= count do print i, " Hellon" i +=1 end
  16. 16. Web Site Links http://tryruby.org http://www.tutorialspoint.com/ruby http://www.ruby- doc.org/docs/ProgrammingRuby http://www.ruby-forum.com/forum/ruby http://stackoverflow.com/questions/tag ged/ruby
  17. 17. THANKS SPRITLE SOFTWARE

×