Download presentation
Presentation is loading. Please wait.
Published byMervin Matthews Modified over 9 years ago
1
Ruby
2
Quick History Name chosen because it was the birthstone of the colleage of the creator Yukihiro Matsumoto First public release Dec 21 1995 Created because Matsumoto wanted “ scripting language that was more powerful than Perl, and more object- oriented than Python." Ruby is a pure OOP language everything is an object. Anything and everything can be overloaded 5.times { print "We *love* Ruby -- it's outrageous!" }
3
Abstract Data Types Again everything in ruby is an object Integers, booleans, and etc are objects and can be modified and used as such e.x. int.to_i => int int.to_int => int int.floor => int int.ceil => int So to create an abstract data type, define a class and then generate an object
4
Ruby ADT Example Class Person_ADT def to_Person(parameter(s))...code... end def make(person1, person2)...code... @person3 = person1 + person2...code... end def terminate_Person(person) puts "I'll be back!" end
5
Ruby Inheritance Ruby supports single inheritance, meaning it can only inherit properties from a single class By default methods are public, though java-like private and protected methods can be defined using the private and protected keywords respectively Subclass methods can override superclass methods using the def
6
Ruby Inheritance Examples class Bird def preen puts "I am cleaning my feathers." end def fly puts "I am flying." end class Penguin < Bird def fly puts "Sorry. I'd rather swim." end p = Penguin.new p.preen p.fly
7
Ruby Dynamic Binding Because Ruby allows for the overriding of methods some mechanism is needed to determine which method is being called when multiple methods with the same name exist Ruby makes use of dynamic dispatching. The calling object is what determines which method is implemented. In the previous example the method fly() is defined twice and executes differently if a Bird or Penguin object is the calling method
8
Ruby Subclasses Once more, everything is an object in Ruby, so rather than having subtypes for subclasses, Ruby just has subclasses that are an extension of the parent object Also Ruby allows nested classes, you can define classes within other classes. A good example of this is inherited classes in Ruby.
9
Nested Classes Ruby allows
10
Ruby Nested Classes Example class A < Object def initialize @y = 0 end class B < Object def initialize @x = 0 end def f #... end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.