Ruby
Programming == Joy
Krupa Suthar
Why named ‘Ruby’?
● Influenced by majorly - Perl
● July Birthstone
Idea behind Ruby
● Yukihiro Matsumoto(‘Matz’) and a colleague were discussing of creating language
with more scripting power than Perl and more object-oriented than Python
● Born in 1993
● Features
○ Truly Object-Oriented
○ Portable
○ Garbage Collector
○ Exception handling
○ Syntactically simple
Get started with Ruby
● Version Manager - rbenv, rvm
● Install
● Irb - Interactive Ruby shell
Is this Object?
Is this Object?
Everything is OBJECT
● Including their properties and actions
● Everything has value, even if that value is nil
● No difference between an expression and statement
● =, .. , &&, ||, or, ::
Ruby’s Flexibility
● Allow user to freely alter its parts
● No restrictions
● Open classes
● Ability to change any inbuilt methods
● Ability to change core classes like Fixnum
Blocks - Truly expressive
● Add closure to method and closure will tell method how to act
● Invoke with yield
● block_given?
● Block with variables
Ruby and Mixin
● Ruby does not support multiple inheritance
● Mixins allows to achieve by requiring multiple modules
● Modules - Collection of methods, constants, other module and class definitions
● Class can access modules by requiring
Ruby’s visual appearance
● Code readable like story
● Simple naming conventions
○ snake_case - Method name
○ CamelCase - Class name
○ @var - Instance variable
○ var - Local variable
○ $var - Global variable
Things you need to know about Ruby
nil and false
● Everything except nil and false is considered true
● In Java and some other languages, 0 and possibly other values such as empty list,
are considered false
Access Modifiers
● Modifiers
● Scopes
Expressive method names
● Methods answering question return with Question mark (?)
E.g. Array#empty?
● ‘Dangerous’ methods end with Exclamation mark (!)
E.g. save!
Singleton methods
● Per-object methods. They are only available on the Object you defined it on.
Message passing, not function calls
● A method call is really a message to another object
Keyword arguments
● Like Python, Ruby also allows to use keyword as argument
Missing methods
● missing_method error
● NameError
RubyGems
● What are Gems?
● Installing Gem
● Bundler
● Using Gems
Thank You !
Any Questions??

Ruby

  • 1.
  • 2.
    Why named ‘Ruby’? ●Influenced by majorly - Perl ● July Birthstone
  • 3.
    Idea behind Ruby ●Yukihiro Matsumoto(‘Matz’) and a colleague were discussing of creating language with more scripting power than Perl and more object-oriented than Python ● Born in 1993 ● Features ○ Truly Object-Oriented ○ Portable ○ Garbage Collector ○ Exception handling ○ Syntactically simple
  • 4.
    Get started withRuby ● Version Manager - rbenv, rvm ● Install ● Irb - Interactive Ruby shell
  • 5.
  • 6.
  • 7.
    Everything is OBJECT ●Including their properties and actions ● Everything has value, even if that value is nil ● No difference between an expression and statement ● =, .. , &&, ||, or, ::
  • 9.
    Ruby’s Flexibility ● Allowuser to freely alter its parts ● No restrictions ● Open classes ● Ability to change any inbuilt methods ● Ability to change core classes like Fixnum
  • 11.
    Blocks - Trulyexpressive ● Add closure to method and closure will tell method how to act ● Invoke with yield ● block_given? ● Block with variables
  • 13.
    Ruby and Mixin ●Ruby does not support multiple inheritance ● Mixins allows to achieve by requiring multiple modules ● Modules - Collection of methods, constants, other module and class definitions ● Class can access modules by requiring
  • 15.
    Ruby’s visual appearance ●Code readable like story ● Simple naming conventions ○ snake_case - Method name ○ CamelCase - Class name ○ @var - Instance variable ○ var - Local variable ○ $var - Global variable
  • 16.
    Things you needto know about Ruby nil and false ● Everything except nil and false is considered true ● In Java and some other languages, 0 and possibly other values such as empty list, are considered false Access Modifiers ● Modifiers ● Scopes
  • 17.
    Expressive method names ●Methods answering question return with Question mark (?) E.g. Array#empty? ● ‘Dangerous’ methods end with Exclamation mark (!) E.g. save! Singleton methods ● Per-object methods. They are only available on the Object you defined it on.
  • 19.
    Message passing, notfunction calls ● A method call is really a message to another object Keyword arguments ● Like Python, Ruby also allows to use keyword as argument Missing methods ● missing_method error ● NameError
  • 21.
    RubyGems ● What areGems? ● Installing Gem ● Bundler ● Using Gems
  • 22.
    Thank You ! AnyQuestions??