0% found this document useful (0 votes)
27 views13 pages

Lecture 1

Ruby was invented by Yukihiro Matsumoto in 1996 and gained popularity with Ruby on Rails in 2005. It is a dynamic, object-oriented language influenced by Perl, Smalltalk, Eiffel and Lisp. The lecture covers Ruby's history, why it is a useful language to learn, and basic principles like its object-oriented nature, indentation conventions, and how to print to the console.

Uploaded by

JITENDRA TIWARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views13 pages

Lecture 1

Ruby was invented by Yukihiro Matsumoto in 1996 and gained popularity with Ruby on Rails in 2005. It is a dynamic, object-oriented language influenced by Perl, Smalltalk, Eiffel and Lisp. The lecture covers Ruby's history, why it is a useful language to learn, and basic principles like its object-oriented nature, indentation conventions, and how to print to the console.

Uploaded by

JITENDRA TIWARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

In this lecture, we will discuss…

▪ Brief history of Ruby


▪ Another programming language to learn? Why?
▪ Basic Ruby principles and conventions
Ruby History
▪  Invented by Yukihiro “Matz” Matsumoto

▪  Version 1.0 released in 1996 (Japan)

▪  Popularized by Ruby on Rails beginning in 2005


Ruby: High Level Overview
▪  Dynamic

▪  Object-oriented
▪ Object-possessed, almost everything is an object

▪  Elegant, expressive and declarative


▪  Terse at times, but extremely readable

▪  Influenced by Perl, Smalltalk, Eiffel and Lisp

“Designed to make programmers happy”


…Java…

public class Print3Times {


public static void main(String[] args){
for(int i = 0; i < 3; i++) {
System.out.println("Hello World!");
}
}
}
…Ruby…
Carried away…
Ruby Basics
▪  2 space indentation for each nested level is encouraged
▪  Not required (unlike Python)

▪  # is used for comments


▪  Use comments in moderation – the code itself should tell the
story

▪  Everything is evaluated!
Printing to Console

▪  puts - Standard Ruby method to print strings to


console (as in put string)
▪  Adds a new line after the printed string
▪  Similar to System.out.println() in Java
▪  Used for most of the examples
▪  p - Prints out internal representation of an object
▪  Debugger-style output
Executing Ruby
Naming Conventions

▪  Variables
▪  Lowercase or snake_case if multiple words

▪  Constants
▪  Either ALL_CAPS or FirstCap

▪  Classes (and Modules)


▪  CamelCase
Drop the Semicolons

▪  Leave semicolons off at the end of the line

▪  Can cram several statements in with a semicolon in


between
▪  Usually highly discouraged
IRB – Interactive Ruby
▪  Console-based interactive Ruby interpreter
▪  REPL (Read Evaluate Print Loop)
▪  Comes with a Ruby installation
▪  Lets you experiment (quickly!) Anything evaluates to
something – no need to
assign to a variable

puts returns nil


Summary
▪  Ruby is extremely expressive
▪  Everything is evaluated

What’s next?

▪  Flow of control in Ruby

You might also like