SlideShare a Scribd company logo
Lets
start coding
with
Ruby
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
I’m
Muntasim Ahmed
Developer @globo
ishkul.com
https://github.com/amuntasim/
https://www.linkedin.com/in/muntasim/
Web Developers?
#include <stdio.h>
int main(){
printf(“I love C!”) /*seriously!!*/
return 0;
}
public class BigBrother{
public static void main(String[] args) {
String msg=“Hello!! Here is your big brother”
System.out.println(msg);
}
}
puts “its really simple! ”
class RubyClass
attr_accessor :v1, :v2
end
r = RubyClass.new
r.v1 = “test”
r.v1 => ‘test’
r.v2 => nil
Thank you Matz!
Ruby Philosophie
“I believe people want to express themselves
when they program. They don’t want to fight
with the language. Programming languages
must feel natural to programmers. I tried to
make people enjoy programming and
concentrate on the fun and creative part of
programming when they use Ruby.”
-- Yukihiro "Matz" Matsumoto, Ruby creator
Why Ruby?
• Its simple
• Easy to write/learn
• Truly object oriented
• Emphasize programming speed!
• Less code, fewer bugs
• Open source
From where to start?!
Installation
• Just google with install ruby with
rvm/rbenv in <Your OS>
• Should be simple as like Ruby 
From where to start?!
IRB = Interactive Ruby
> Irb
Or
tryruby.org
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Inside Ruby
Everything is an object
3.odd? => true
“string”.length => 6
[].empty? => true
“abc”.methods => [..,..,..]
Duck Typing
?!
It doesn’t mind
• if you don’t like ‘;’ at the end
• even a method without ()
• If you want to express in your way
• and many more..
Happy Programmer 
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Variables
• Any plain, lowercase word
• a, my_variable and rubyconf2017
• > a => undefined local variable or method `a`
• > a = ‘hello’ => hello
• > a => hello
• > a = 1 => 1 
Number
• Integers (Fixnum), Float
• 1, -3002, 2.3, 1233.1e12
• > 1.class => Fixnum
• >1.3.class => Float
• >1.3e12.class => Float
• >1 + 2 => 3
• >1.4+ 4 => 5.4
Strings
• Anything surrounded by quotes ‘’ or “”
• ‘RubyConf 2017’, “Muntasim”
• > a = ‘hello’ => hello
• > a => hello
• > a.upcase => HELLO
• > a.upcase.object_id => 2212289940
• > a.object_id => 2212352200
• > a << ‘ world’ => hello world
Symbols
• Start with a colon, look like words
• Uses same object reference
• Useful for keys
• :test, :a
• >"test".object_id => 2212252220
• >"test".object_id => 2212236940
• > :test.object_id => 196968
• > :test.object_id => 196968
Constants
• variables, starts with a capital
• Foo, Conf_Date
• :test, :a
 Foo = ‘bar’ => bar
 Foo = ‘dum’ =>’dum’ #warning.
 if something == Foo
#do something
end
Methods
def hi
puts ‘Hi there!’
end
 hi => Hi there!
def hello(name)
puts “Hello #{name}!”
end
 hello ‘khoka’ => ‘Hi khoka!’
Arrays
• A list surrounded by square brackets
• [1,2,4]
• [‘a’, ‘B’, 1] 
 a = [1,3,5,’7’, ‘e’] => [1,3,5,’7’, ‘e’]
 a[2] => 3
 b = [5,6] => [5,6]
 a+b => [1,3,5,’7’, ‘e’, 5,6]
 ….
Hashes
• A list surrounded by curly braces
• {:a => 2, b: ‘3’}
 a = {:a => 2, b: ‘3’} => {:a => 2, b: ‘3’}
 a[:a] => 2, a[:b] => ‘3’
 a.keys => [:a, :b]
 ….
Classes
class Car
attr_accessor :wheels, :color
end
 c = Car.new => #<Car:0x00000107b09840>
 c2 = Car.new =>#<Car:0x00000107b00a60>
 c.color = ‘white’ => white
 c.color => white
 c2.color => nil
class Car
attr_accessor :wheels, :color
def initialize(wheels, color)
self. wheels = wheels
self. color = color
end
def color_and_wheels
“#{color} color with #{wheels} ‘wheels’)”
end
end
 c = Car.new(4, ‘white’) => #<Car0x00000b09840 .....>
 c.color_and_wheels => ‘white color with 4 wheels’
Classes (Open to modify)
class Bird
def make_sound
p “ka-ka-ka”
end
def color
p “black”
end
end
b = Bird.new
b.make_sound => ‘ka-ka-ka’
b.color => ‘black’
Classes (Open to modify)
class Bird
def make_sound
p “kuhu :D ”
end
def name
p “a name”
end
b = Bird.new
b.make_sound => ‘kuhu :D’
b.color => ‘black’
b.name => ‘a name’
Don’t like the sound? Just open the class and
modify it
Module
 Like classes, modules contain methods and
constants but don’t have instances.
 encourage modular design
 Ruby doesn’t support multiple inheritance
but can have that behavior by modules
Module
module M
def m1
end
end
module M
class C
end
end
M.new c = M::C.new
Module
class Thing < Parent
include MathFunctions
include Taggable
include Persistence
end
module Feature
def feature1
p ‘feature1’
end
def feature2
p ‘feature2’
end
end
module Habits
def habit1
p ‘habit1’
end
def habit2
p ‘habit2’
end
end
class Parent
def a1
p ‘a1’
end
end
class Thing < Parent
include Feature
include Habits
end
t = Thing.new
t.a1 => ‘a1’
t.feature1 => ‘feature1’
t.habit2 => ‘habit2’
More on Ruby Basics
• http://rubymonk.com/
• http://tryruby.org/
• http://rubykoans.com/
• http://ruby.learncodethehardway.org/
• http://poignant.guide/ (funny!)
Ruby eco system
• RVM/rbenv
• RubyGems
• Bundler
• Git/github
Ruby vs Ruby on Rails(aka Rails)
• Rails is written in the Ruby
• Rails uses many Ruby gems
• Rails is a framework
• Rails is used to build web apps
rubyonrails.org
Editors
• RubyMine
• Sublime Text
• Textmate
• Vim
• Emacs
• Or whatever you like
References:
• https://www.ruby-lang.org/en/
• https://dzone.com/refcardz/essential-ruby
• http://www.jasimabasheer.com/posts/meta_i
ntroduction_to_ruby.html
• http://curriculum.railsbridge.org/docs/

More Related Content

PDF
Intro to OAuth
KEY
Make GUI Apps with Shoes
PDF
Ruby on Rails
PDF
Intro to jquery
PDF
Functional testing with capybara
PDF
Beware sharp tools
PDF
[ WrocLoveRb 2012] user perspective testing using ruby
PDF
Let jQuery Rock Your World
Intro to OAuth
Make GUI Apps with Shoes
Ruby on Rails
Intro to jquery
Functional testing with capybara
Beware sharp tools
[ WrocLoveRb 2012] user perspective testing using ruby
Let jQuery Rock Your World

Similar to Rubyconf Bangladesh 2017 - Lets start coding in Ruby (20)

PDF
Ruby Language - A quick tour
KEY
Desarrollando aplicaciones web en minutos
KEY
An introduction to Ruby
KEY
Intro to Ruby - Twin Cities Code Camp 7
PDF
Designing Ruby APIs
KEY
PDF
Blocks by Lachs Cox
PDF
Ruby 入門 第一次就上手
PDF
Design Patterns the Ruby way - ConFoo 2015
PPTX
Intro to ruby
PPTX
Ruby Metaprogramming
PPT
Groovy presentation
PDF
Ruby is Awesome
PDF
Write your Ruby in Style
PDF
How to make a large C++-code base manageable
PPTX
The Metasploit Way TO USE IT IN DA PPT.pptx
PDF
Deep Dive Into Swift
PPT
Object Oriented Programming
PDF
Automated Testing with Ruby
PPTX
Code for Startup MVP (Ruby on Rails) Session 2
Ruby Language - A quick tour
Desarrollando aplicaciones web en minutos
An introduction to Ruby
Intro to Ruby - Twin Cities Code Camp 7
Designing Ruby APIs
Blocks by Lachs Cox
Ruby 入門 第一次就上手
Design Patterns the Ruby way - ConFoo 2015
Intro to ruby
Ruby Metaprogramming
Groovy presentation
Ruby is Awesome
Write your Ruby in Style
How to make a large C++-code base manageable
The Metasploit Way TO USE IT IN DA PPT.pptx
Deep Dive Into Swift
Object Oriented Programming
Automated Testing with Ruby
Code for Startup MVP (Ruby on Rails) Session 2
Ad

More from Ruby Bangladesh (7)

PPTX
RubyConf Bangladesh 2017 - Introduction to Ruby on Rails
PPTX
RubyConf Bangladesh 2017 - Core Ruby: How it works
PPTX
RubyConf Bangladesh 2017 - Speed up your API/backend
PPTX
RubyConf Bangladesh 2017 - Craft beautiful code with Ruby DSL
PPTX
RubyConf Bangladesh 2017 - Which language should I choose
PPTX
RubyConf Bangladesh 2017 - Elixir for Rubyists
PPTX
RubyConf Bangladesh 2017 - Rails buggy code
RubyConf Bangladesh 2017 - Introduction to Ruby on Rails
RubyConf Bangladesh 2017 - Core Ruby: How it works
RubyConf Bangladesh 2017 - Speed up your API/backend
RubyConf Bangladesh 2017 - Craft beautiful code with Ruby DSL
RubyConf Bangladesh 2017 - Which language should I choose
RubyConf Bangladesh 2017 - Elixir for Rubyists
RubyConf Bangladesh 2017 - Rails buggy code
Ad

Recently uploaded (20)

PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Nekopoi APK 2025 free lastest update
PPTX
assetexplorer- product-overview - presentation
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
history of c programming in notes for students .pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
ai tools demonstartion for schools and inter college
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Digital Strategies for Manufacturing Companies
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
medical staffing services at VALiNTRY
PPT
Introduction Database Management System for Course Database
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
System and Network Administraation Chapter 3
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Digital Systems & Binary Numbers (comprehensive )
Nekopoi APK 2025 free lastest update
assetexplorer- product-overview - presentation
Adobe Illustrator 28.6 Crack My Vision of Vector Design
history of c programming in notes for students .pptx
Wondershare Filmora 15 Crack With Activation Key [2025
ai tools demonstartion for schools and inter college
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Digital Strategies for Manufacturing Companies
CHAPTER 2 - PM Management and IT Context
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
top salesforce developer skills in 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Which alternative to Crystal Reports is best for small or large businesses.pdf
medical staffing services at VALiNTRY
Introduction Database Management System for Course Database
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
System and Network Administraation Chapter 3
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

Rubyconf Bangladesh 2017 - Lets start coding in Ruby

  • 5. #include <stdio.h> int main(){ printf(“I love C!”) /*seriously!!*/ return 0; }
  • 6. public class BigBrother{ public static void main(String[] args) { String msg=“Hello!! Here is your big brother” System.out.println(msg); } }
  • 7. puts “its really simple! ” class RubyClass attr_accessor :v1, :v2 end r = RubyClass.new r.v1 = “test” r.v1 => ‘test’ r.v2 => nil
  • 9. Ruby Philosophie “I believe people want to express themselves when they program. They don’t want to fight with the language. Programming languages must feel natural to programmers. I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby.” -- Yukihiro "Matz" Matsumoto, Ruby creator
  • 10. Why Ruby? • Its simple • Easy to write/learn • Truly object oriented • Emphasize programming speed! • Less code, fewer bugs • Open source
  • 11. From where to start?! Installation • Just google with install ruby with rvm/rbenv in <Your OS> • Should be simple as like Ruby 
  • 12. From where to start?! IRB = Interactive Ruby > Irb Or tryruby.org
  • 15. Everything is an object 3.odd? => true “string”.length => 6 [].empty? => true “abc”.methods => [..,..,..]
  • 17. It doesn’t mind • if you don’t like ‘;’ at the end • even a method without () • If you want to express in your way • and many more.. Happy Programmer 
  • 20. Variables • Any plain, lowercase word • a, my_variable and rubyconf2017 • > a => undefined local variable or method `a` • > a = ‘hello’ => hello • > a => hello • > a = 1 => 1 
  • 21. Number • Integers (Fixnum), Float • 1, -3002, 2.3, 1233.1e12 • > 1.class => Fixnum • >1.3.class => Float • >1.3e12.class => Float • >1 + 2 => 3 • >1.4+ 4 => 5.4
  • 22. Strings • Anything surrounded by quotes ‘’ or “” • ‘RubyConf 2017’, “Muntasim” • > a = ‘hello’ => hello • > a => hello • > a.upcase => HELLO • > a.upcase.object_id => 2212289940 • > a.object_id => 2212352200 • > a << ‘ world’ => hello world
  • 23. Symbols • Start with a colon, look like words • Uses same object reference • Useful for keys • :test, :a • >"test".object_id => 2212252220 • >"test".object_id => 2212236940 • > :test.object_id => 196968 • > :test.object_id => 196968
  • 24. Constants • variables, starts with a capital • Foo, Conf_Date • :test, :a  Foo = ‘bar’ => bar  Foo = ‘dum’ =>’dum’ #warning.  if something == Foo #do something end
  • 25. Methods def hi puts ‘Hi there!’ end  hi => Hi there! def hello(name) puts “Hello #{name}!” end  hello ‘khoka’ => ‘Hi khoka!’
  • 26. Arrays • A list surrounded by square brackets • [1,2,4] • [‘a’, ‘B’, 1]   a = [1,3,5,’7’, ‘e’] => [1,3,5,’7’, ‘e’]  a[2] => 3  b = [5,6] => [5,6]  a+b => [1,3,5,’7’, ‘e’, 5,6]  ….
  • 27. Hashes • A list surrounded by curly braces • {:a => 2, b: ‘3’}  a = {:a => 2, b: ‘3’} => {:a => 2, b: ‘3’}  a[:a] => 2, a[:b] => ‘3’  a.keys => [:a, :b]  ….
  • 28. Classes class Car attr_accessor :wheels, :color end  c = Car.new => #<Car:0x00000107b09840>  c2 = Car.new =>#<Car:0x00000107b00a60>  c.color = ‘white’ => white  c.color => white  c2.color => nil
  • 29. class Car attr_accessor :wheels, :color def initialize(wheels, color) self. wheels = wheels self. color = color end def color_and_wheels “#{color} color with #{wheels} ‘wheels’)” end end  c = Car.new(4, ‘white’) => #<Car0x00000b09840 .....>  c.color_and_wheels => ‘white color with 4 wheels’
  • 30. Classes (Open to modify) class Bird def make_sound p “ka-ka-ka” end def color p “black” end end b = Bird.new b.make_sound => ‘ka-ka-ka’ b.color => ‘black’
  • 31. Classes (Open to modify) class Bird def make_sound p “kuhu :D ” end def name p “a name” end b = Bird.new b.make_sound => ‘kuhu :D’ b.color => ‘black’ b.name => ‘a name’ Don’t like the sound? Just open the class and modify it
  • 32. Module  Like classes, modules contain methods and constants but don’t have instances.  encourage modular design  Ruby doesn’t support multiple inheritance but can have that behavior by modules
  • 33. Module module M def m1 end end module M class C end end M.new c = M::C.new
  • 34. Module class Thing < Parent include MathFunctions include Taggable include Persistence end
  • 35. module Feature def feature1 p ‘feature1’ end def feature2 p ‘feature2’ end end module Habits def habit1 p ‘habit1’ end def habit2 p ‘habit2’ end end class Parent def a1 p ‘a1’ end end class Thing < Parent include Feature include Habits end t = Thing.new t.a1 => ‘a1’ t.feature1 => ‘feature1’ t.habit2 => ‘habit2’
  • 36. More on Ruby Basics • http://rubymonk.com/ • http://tryruby.org/ • http://rubykoans.com/ • http://ruby.learncodethehardway.org/ • http://poignant.guide/ (funny!)
  • 37. Ruby eco system • RVM/rbenv • RubyGems • Bundler • Git/github
  • 38. Ruby vs Ruby on Rails(aka Rails) • Rails is written in the Ruby • Rails uses many Ruby gems • Rails is a framework • Rails is used to build web apps rubyonrails.org
  • 39. Editors • RubyMine • Sublime Text • Textmate • Vim • Emacs • Or whatever you like
  • 40. References: • https://www.ruby-lang.org/en/ • https://dzone.com/refcardz/essential-ruby • http://www.jasimabasheer.com/posts/meta_i ntroduction_to_ruby.html • http://curriculum.railsbridge.org/docs/

Editor's Notes

  • #12: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #14: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #17: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #21: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #22: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #23: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #24: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #25: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #26: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #27: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #28: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #29: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #31: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #32: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #33: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #34: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #35: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #38: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #39: - deals with objects, not the classes. - If the object has the method, it can call the method
  • #40: - deals with objects, not the classes. - If the object has the method, it can call the method