ruby cucumber training | ruby cucumber course | ruby cucumber online training
Ruby
-
Upload
chabucaloca -
Category
Documents
-
view
217 -
download
0
description
Transcript of Ruby
![Page 1: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/1.jpg)
Presented By
Carl Zumbano and Sui Cheng
CS151 – Object Oriented ProgrammingMay 10, 2001
![Page 2: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/2.jpg)
Ruby: An Introduction
• Created by Yukihiro Matsumoto in 1993 (named after his birthstone)
• Inspired (in part) by Eiffel and Ada
• Pure OO language (even the number 1 is an instance of a class)
• Highly portable, works on Linux, UNIX, DOS, Windows 95/98/NT/2K, Mac, etc.
![Page 3: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/3.jpg)
Ruby: An Introduction
• Freely available and open-source.• More popular than Python in Japan,
probably b/c it handles mutibyte character sets so easily.
• Syntax is readable and easy to learn.• Being used for text processing, web apps,
general system administration, and AI and math research.
![Page 4: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/4.jpg)
Ruby: the Language
• No multiple inheritance, but modules allow the importing of methods.
• Has garbage collection.
• Exception handling, like Java.
• Any class or instance can be extended anytime (even during runtime)
• Allows operator overloading.
![Page 5: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/5.jpg)
Ruby: the Language
• Can be extended with Ruby or low-level C.
• No type declaration.
• Has iterators, methods which accept blocks for user-defined control structures (like loops)
• Emacs, TextPad, and Vim all have support available for Ruby.
![Page 6: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/6.jpg)
Ruby: A Demonstration#Person Classclass Person
attr_accessor :name, :age def initialize(name, age)
@name = name @age = age.to_i
end def inspect
"#@name (#@age)" end
end
#Usage of the classp1 = Person.new('elmo', 4) p2 = Person.new('zoe', 7)
#Resultsp1 # -> elmo (4) p2 # -> zoe (7)
![Page 7: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/7.jpg)
Ruby: A Demonstration
Now let’s take a look at Ruby in action…
![Page 8: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/8.jpg)
Ruby Vs Java / C++
• Ruby– “Ruby”.length
– -5.0.abs
• C++ / Java– strlen(“Ruby”);
– s.length();
– abs(-5.0);
– number = Math.abs(number);
![Page 9: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/9.jpg)
Advantages using Ruby against Java and C++
• Allow pass by code block • Support Regular Expression• Cleaner code
– No need to declare variables– Simple syntax (semi-colon is optional)– Every thing is an object, even a number. No
need to call separate function.– Simple object get/set methods declaration
![Page 10: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/10.jpg)
Advantages (continue)
• Classes and modules are never closed. • Better Access Control
– Dynamic access control– Private methods never accessible directly by
another object
• Portable and extensible with third-party library
• Interactive environment
![Page 11: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/11.jpg)
Disadvantages using Ruby against Java and C++
• No multiple inheritance– However, Ruby offers multiple-inheritance-like capabilities
• Ruby is a scripting language– However, Ruby can access to OS features, do same thing as
Perl and Python
• Different syntax and method definition style– Return statement is optional– Use of expression interpretation– Braces not needed in control statements (if, while)– Instance variable must preceded by “@”
![Page 12: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/12.jpg)
Disadvantages (continue)
• Potential thread starvation in multi-threading– Use in-process thread [non-native]– However, it is lightweight and efficient
![Page 13: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/13.jpg)
Closing
• Free download for Unix/Windows
• Applications includes:– X11 window manager, GUIs, managing server
machines and databases.
• Want to know more:– Visit http://www.ruby-lang.org
![Page 14: Ruby](https://reader035.fdocuments.in/reader035/viewer/2022062410/5695d1961a28ab9b029724ef/html5/thumbnails/14.jpg)
Ruby: References
• The Ruby Programming Language by Yukio Matsumoto; Addison Wesley Professional, 2000.
• Programming Ruby: A Pragmatic Programmer's Guide by David Thomas and Andrew Hunt; Addison-Wesley Pub Co, 2000.