Published on May 5, 2014
Introduction to Ruby Shane Cao Dinesh Devkota Robert Laurent
What is Ruby? •A Cross-Platform, interpreted and object-oriented language •Designed on the Principle of Least Surprise
History of Ruby •Created by a Japanese developer by the name of Yukihiro Matsumoto in 1993 (known in online communities as ‘Matz’)
• “I wanted to minimize my frustration during programming, so I want to minimize my effort in programming. That was my primary goal in designing Ruby.” - Matz • Was influenced mainly by Perl and Python. Matz wanted a genuine object-oriented, easy- to-use scripting language. Since he could find one, he decided to make it himself.
• In 2004, there was a massive surge of interest in Ruby, with the introduction of the Ruby on Rails Web application framework. • Open Source (Free) – This means that it’s in the budget! • Ported to run on many different computer platforms and architectures.
Cool Features of Ruby • Common Gateway Interface (CGI Scripts) • Can be embedded in HTML • Used to develop Internet and Intranet Apps • Syntax is clean and easy to understand • Problems are scalable and easy to maintain
Downloading Ruby http://www.rubyinstaller.org/downloads Available for Windows, Macintosh, and Linux 32-bit and 64-bit versions available
• Editing Ruby Files – Can be done with a plain-text editor • Notepad • VI • As long as it is not a word processor – Any folder can be used to store your files
• Getting Started – After installing Ruby • ruby.exe can be used at a command prompt (DOS shell) • rubyw.exe can be used to launch a GUI
Things to Know Before Coding with Ruby • All Ruby files must end with a .rb extension – For example: foo.rb • White spaces and tabs are ignored – Except when they appear in strings • Operations at the end indicate a continuation of a statement
Thing to Know (Continued) • Identifiers are names of variables, constants, and methods • Variable names are case sensitive – foo and FOO are two different identifiers • Identifier names may consist of alphanumeric characters and an underscore (_)
Syntax •Covering Ruby in comparison with other languages. – May assist users that are new to Ruby learn it easier.
type declaration • No need to define the data type when declaring a variable • Ruby is looser about types than Java – – The data type of the variable can change throughout the program. i=2 →2 i=“hello” →“hello”
Differences • Java – There is a maximum value for integers – There is a maximum value for long • Ruby – There is no maximum! – X=2341132451345123451345141143254135124….32 Which is valid!
What does it do in console? Arithmetic Operators. 9/3 2+3 2**5 2*5 →3 →5 →32 →15 • "I love espresso".length → 15 • "Eric".reverse →"cirE“ • puts "dinesh".upcase →DINESH • # I'm a full line comment! • =begin I'm a comment! I don't need any # symbols. =end
Printing and retrieving • Want to print something on screen? •Need to get something from the console? text = gets.chomp #same as scanner object in Java • It stores values from the console to the variable text.
String Manipulation in Ruby • Strings can be multiplied by integers – Concatenates string repeatedly –“hello ”*3 → “hello hello hello “ BUT “hello”+3 → “TypeError: Can’t convert fixnum into String … blah blah “
Loops •Like for loop While loop! Catch!
IF Statements Catch!
Logical Operators •Logical Operators work the same as in Java •== != >= <= < > Valid • One More Operator which are not in other languages . <=>
Constant in Ruby • Ruby Doesn’t Have Constants! – So a user can define a variable on the top of program and it will accessible everywhere. CMPS_CONSTANT =“ROCKS!” o Trying to change it generates warning but one can change it. (BAD ABOUT RUBY)
• Ruby doesn’t have a Main Method • No parenthesis! Unlike many other languages! • Define method with “def”
How to run Ruby • Array count • Uses for loop to display all numbers in array
Another way to display Array’s • Calling array using a block. • Blocks are just chunks of code that you can pick up an drop into another method as an input.
Building an Array from scratch
More Resources Ruby in Twenty Minutes: https://www.ruby-lang.org/en/documentation/quickstart/ Ruby on Rails Tutorial http://www.railstutorial.org/ Try Ruby within your browser! http://tryruby.org/levels/1/challenges/0
Discrete element method modelling (DEM) has proven over many years to be a powerfu...
Segregation Testing to confirm packer isolation and well integrity. Monitor w...
A small presentation of History matching and a case study on it. Also on Gas mater...
Geschrieben von Matz am 13.7.2001. Ruby introduction presentation at New York City CTO club by Jim Menard on July 10, 2001.
Ruby. Einfach programmieren. Agenda des Vortrags. Historie Stamm der Sprache Facts Download Syntax Kontrollstrukturen Datenstrukturen ...
Contrast Ruby for common problems and contrast it with perl and php :) To show non-programmers that ruby can be very nice, use something that is a ...
Ruby Language overviewBy: mohamad amin Rastgoo The History of Ruby created by Yukihiro Matsumoto (more affectiona...
Ruby Prize 2016 nominations are now open. Ruby Prize 2016 nominations are now being accepted for new and outstanding members in the Ruby community.
Fast and searchable Ruby documentation for core, standard libraries, and rubygems. Available in both RDoc and Yard format. Plus, links to tutorials, guides ...
Ruby – A free PowerPoint PPT presentation (displayed as a Flash slide show) on PowerShow.com - id: 1cd134-ZDc1Z
View Ruby On Rails presentations online, safely and virus-free! Many are downloadable. Learn new and interesting things. Get ideas for your own presentations.
README.rdoc RubyPowerpoint – Parser for Powerpoint(pptx) files. ruby_powerpoint is a Ruby gem that can extract title, content and images from Powerpont ...