SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
module Exlabs
class Presentation
attr_reader :author, :title, :date
def self.ish
new(author: 'Wojtek Widenka',
title: 'Selfish Presentation')
end
def initialize(params)
@author = params.fetch(:author, 'unknown')
@title = params.fetch(:title, 'unknown')
@date = params.fetch(:date, Date.today)
end
end
end
module Exlabs
class Presentation
attr_reader :author, :title, :date
puts "1: #{self}"
def self.ish
puts "2: #{self}"
new(author: 'Wojtek Widenka',
title: 'Selfish Presentation')
end
def initialize(params = {})
@author = params.fetch(:author, 'unknown')
@title = params.fetch(:title, 'unknown')
@date = params.fetch(:date, Date.today)
puts "3: #{self}"
end
def foo
puts "4: #{self}"
end
end
end
module Exlabs
class Presentation
attr_reader :author, :title, :date
puts "1: #{self}t#{self.class}"
def self.ish
puts "2: #{self}t#{self.class}"
new(author: 'Wojtek Widenka',
title: 'Selfish Presentation')
end
def initialize(params = {})
@author = params.fetch(:author, 'unknown')
@title = params.fetch(:title, 'unknown')
@date = params.fetch(:date, Date.today)
puts "3: #{self}t#{self.class}"
end
def foo
puts "4: #{self}t#{self.class}"
end
end
end
# enter the text from left side
1: Exlabs::Presentation Class
=> :foo
> object = Exlabs::Presentation.ish
2: Exlabs::Presentation Class
3: #<Exlabs::Presentation:0x007f8fa9eac028> Exlabs::Presentation
=> #<Exlabs::Presentation:0x007f8fa9eac028 @author="Wojtek
Widenka", @title="Selfish Presentation", @date=#<Date: 2016-10-26
((2457688j,0s,0n),+0s,2299161j)>>
> object.foo
4: #<Exlabs::Presentation:0x007f8fa9eac028> Exlabs::Presentation
=> nil
SystemStackError: stack level too deep
def self.h
@h = 'st'
puts h
end
module Exlabs
class Examples
->
end
end
def self.a
puts a
end
def self.b
puts self.b
end
st
=> nil
def self.c
c = 'st'
puts c
end
def self.d
d = 'st'
puts self.d
end
def self.e
self.e = 'st'
puts e
end
def self.f
self.f = 'st'
puts self.f
end
def self.g
@g = 'st'
puts @g
end
> Exlabs::Examples.a
NoMethodError: undefined method `e='
for Exlabs::Examples:Class
def self.i
@i = 'st'
puts self.i
end
SystemStackError: stack level too deep
def q
@q = 'st'
puts q
end
module Exlabs
class Examples
->
end
end
def j
puts j
end
def k
puts self.k
end
st
=> nil
def l
l = 'st'
puts l
end
def m
m = 'st'
puts self.m
end
def n
self.n = 'st'
puts n
end
def o
self.o = 'st'
puts self.o
end
def p
@p = 'st'
puts @p
end
> Exlabs::Examples.new.j
NoMethodError: undefined method `n=' for
#<Exlabs::Examples:0x007f8130af82d8>
def r
@r = 'st'
puts self.r
end
SystemStackError: stack level too deep
def self.h
@h = 'st'
puts h
end
module Exlabs
class Examples
->
end
end
def self.a
puts a
end
def self.b
puts self.b
end
st
=> nil
def self.c
c = 'st'
puts c
end
def self.d
d = 'st'
puts self.d
end
def self.e
self.e = 'st'
puts e
end
def self.f
self.f = 'st'
puts self.f
end
def self.g
@g = 'st'
puts @g
end
> Exlabs::Examples.a
NoMethodError: undefined method `e='
for Exlabs::Examples:Class
def self.i
@i = 'st'
puts self.i
end
SystemStackError: stack level too deep
def q
@q = 'st'
puts q
end
module Exlabs
class Examples
->
end
end
def j
puts j
end
def k
puts self.k
end
st
=> nil
def l
l = 'st'
puts l
end
def m
m = 'st'
puts self.m
end
def n
self.n = 'st'
puts n
end
def o
self.o = 'st'
puts self.o
end
def p
@p = 'st'
puts @p
end
> Exlabs::Examples.new.j
NoMethodError: undefined method `n=' for
#<Exlabs::Examples:0x007f8130af82d8>
def r
@r = 'st'
puts self.r
end
module Exlabs
class Presentation
attr_reader :author, :title, :date
puts "1: #{self}t#{self.class}"
def self.ish
puts "2: #{self}t#{self.class}"
new(author: 'Wojtek Widenka',
title: 'Selfish Presentation')
end
class << self
puts "5: #{self}t#{self.class}"
def bar
puts "6: #{self}t#{self.class}"
end
def self.foobar
puts "7: #{self}t#{self.class}"
end
end
def initialize(params = {})
@author = params.fetch(:author, 'unknown')
@title = params.fetch(:title, 'unknown')
@date = params.fetch(:date, Date.today)
puts "3: #{self}t#{self.class}"
end
def foo
puts "4: #{self}t#{self.class}"
end
end
end
# enter the text from left side
1: Exlabs::Presentation Class
5: #<Class:Exlabs::Presentation> Class
=> :foo
> object = Exlabs::Presentation.ish
2: Exlabs::PresentationClass
3: #<Exlabs::Presentation:0x007fce5514b218> Exlabs::Presentation
=> #<Exlabs::Presentation:0x007fce5514b218 @author=[…]>
> object.foo
4: #<Exlabs::Presentation:0x007fce5514b218> Exlabs::Presentation
=> nil
> object.bar
NoMethodError: undefined method `bar' for #<Exlabs::Presentation:0x007fce5514b218>
> Exlabs::Presentation.bar
6: Exlabs::Presentation Class
=> nil
> object.foobar
NoMethodError: undefined method `foobar' for #<Exlabs::Presentation:0x007fce5514b218>
> Exlabs::Presentation.foobar
NoMethodError: undefined method `foobar' for Exlabs::Presentation:Class
> Exlabs::Presentation.singleton_class.foobar
7: #<Class:Exlabs::Presentation> Class
=> nil
module Exlabs
class Presentation
attr_reader :author, :title, :date
puts "1: #{self}t#{self.class}"
def self.ish
puts "2: #{self}t#{self.class}"
new(author: 'Wojtek Widenka',
title: 'Selfish Presentation')
end
class << self
puts "5: #{self}t#{self.class}"
def bar
puts "6: #{self}t#{self.class}"
end
def self.foobar
puts "7: #{self}t#{self.class}"
end
end
def initialize(params = {})
@author = params.fetch(:author, 'unknown')
@title = params.fetch(:title, 'unknown')
@date = params.fetch(:date, Date.today)
puts "3: #{self}t#{self.class}"
end
def foo
puts "4: #{self}t#{self.class}"
end
end
end
module Exlabs
class Stranger
class << self
puts "8: #{self}t#{self.class}"
def bar
puts "9: #{self}t#{self.class}"
end
private
def private_method
puts 'Just a text'
end
end
class << Presentation
puts "10: #{self}t#{self.class}"
def bar
puts "11: #{self}t#{self.class}"
end
end
end
end
# enter the text from left side
8: #<Class:Exlabs::Stranger> Class
10: #<Class:Exlabs::Presentation> Class
=> :bar
> Exlabs::Stranger.bar
9: Exlabs::Stranger Class
=> nil
> Exlabs::Stranger.private_method
NoMethodError: private method `private_method'
called for Exlabs::Stranger:Class
> Exlabs::Presentation.bar
11: Exlabs::Presentation Class
=> nil
str1 = 'String 1'
str2 = 'String 2'
class << String
def foo
puts 'foo called'
puts self
end
end
class << str1
def bar
puts 'bar called'
puts self
end
end
> str1.foo
NoMethodError: undefined method `foo' for "String 1":String
> String.foo
foo called
String
=> nil
> str1.bar
bar called
String 1
=> nil
> str2.bar
NoMethodError: undefined method `bar' for "String 2":String
> String.singleton_class.method_defined? :bar
=> false
> str1.singleton_class.method_defined? :bar
=> true
> str2.singleton_class.method_defined? :bar
=> false
str1 = 'String 1'
str2 = 'String 2'
class << String
def foo
puts 'foo called'
puts self
end
end
class << str1
def bar
puts 'bar called'
puts self
end
end
> str1.foo
NoMethodError: undefined method `foo' for "String 1":String
> String.foo
foo called
String
=> nil
> str1.bar
bar called
String 1
=> nil
> str2.bar
NoMethodError: undefined method `bar' for "String 2":String
> String.singleton_class.method_defined? :bar
=> false
> str1.singleton_class.method_defined? :bar
=> true
> str2.singleton_class.method_defined? :bar
=> false
▸ ruby is tricky
▸ in ruby everything is an object
▸ from ruby implementation point of view Class is slightly different than Object
struct RObject {
struct RBasic basic;
union {
struct {
uint32_t numiv;
VALUE *ivptr;
void *iv_index_tbl;
} heap;
VALUE ary[ROBJECT_EMBED_LEN_MAX];
} as;
};
struct RBasic {
VALUE flags;
const VALUE klass;
}
struct RClass {
struct RBasic basic;
VALUE super;
rb_classext_t *ptr;
struct rb_id_table *m_tbl;
};
▸ classes contains methods while objects variables (this is confusing, not sure if
can explain)
▸ when we implementing new class
class NewClass
def new_method
end
end
▸ we are creating new instance of Class (we can use instead Class.new syntax)
▸ There is also constructed singleton class (eigenclass, metaclass) in which methods
are stored
▸ Since it is singleton it cannot be duplicated and is connected always with one object
▸ ruby is tricky, metaclass is transparent, so calling #class on object will ommit it
"Nathan".is_a?(BasicObject) # => true "Nathan" is an object.
"Nathan".class #=> String "Nathan" is an instance of the String class.
"Nathan".is_a?(Class) #=> false "Nathan" is not a class.
"Nathan".superclass # NoMethodError "Nathan" has no superclass, because "Nathan" is not a class.
String.is_a?(BasicObject) #=> true String is an object.
String.class #=> Class String is an instance of the Class class.
String.superclass #=> Object String's superclass is Object.
Object.is_a?(BasicObject) #=> true Object is an object.
Object.class #=> Class Object is an instance of the Class class.
Object.superclass #=> BasicObject Object's superclass is BasicObject.
BasicObject.is_a?(BasicObject) #=> true BasicObject is an object.
BasicObject.class #=> Class BasicObject is an instance of the Class class
BasicObject.superclass #=> nil BasicObject's superclass is nil.
nil.is_a?(BasicObject) #=> true nil is an object.
nil.class #=> NilClass nil is an instance of the NilClass class
nil.superclass # NoMethodError nil has no superclass, because it is not a class.
Class.is_a?(BasicObject) #=> true Class is an object.
Class.class #=> Class Class is an instance of the Class class.
# this is probably the most important part.
Class.superclass #=> Module Class's superclass is Module
# 2nd most important part
Module.is_a?(BasicObject) #=> true Module is an object
Module.class #=> Class Module is an instance of the Class class. # 3rd
Module.superclass #=> Object Module's superclass is Object # 4th
Object.is_a?(BasicObject) #=> true Object is an object.
Object.class #=> Class Object is an instance of the Class class.
Object.superclass #=> BasicObject Object's superclass is BasicObject.
BasicObject.is_a?(BasicObject) #=> true BasicObject is an object.
BasicObject.class #=> Class BasicObject is an instance of the Class class
BasicObject.superclass #=> nil BasicObject's superclass is nil.
nil.is_a?(BasicObject) #=> true nil is an object.
nil.class #=> NilClass nil is an instance of the NilClass class
nil.superclass # NoMethodError nil has no superclass, because it is not a class.

Contenu connexe

Tendances

Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in ScalaJorge Vásquez
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Jorge Vásquez
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021Jorge Vásquez
 
Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python ClassJim Yeh
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaJorge Vásquez
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and ClosuresSandip Kumar
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUIBongwon Lee
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 

Tendances (20)

Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
Scala idioms
Scala idiomsScala idioms
Scala idioms
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
 
Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python Class
 
Exploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in ScalaExploring ZIO Prelude: The game changer for typeclasses in Scala
Exploring ZIO Prelude: The game changer for typeclasses in Scala
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
Scala
ScalaScala
Scala
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Objective-c Runtime
Objective-c RuntimeObjective-c Runtime
Objective-c Runtime
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
 
SWIFT 3
SWIFT 3SWIFT 3
SWIFT 3
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 

En vedette

formatos de imagen
formatos de imagenformatos de imagen
formatos de imagenmmaaee
 
Estadística General
Estadística GeneralEstadística General
Estadística GeneralFree TIC
 
Iniciando c
Iniciando cIniciando c
Iniciando c____
 
Estrategias
EstrategiasEstrategias
EstrategiasFree TIC
 
3Com 3C595-TX-SER
3Com 3C595-TX-SER3Com 3C595-TX-SER
3Com 3C595-TX-SERsavomir
 
experimento sólido-líquido
experimento sólido-líquidoexperimento sólido-líquido
experimento sólido-líquidoPily Pparra
 
آزمون پیشرفت تحصیلی پایه دهم کاردانش
آزمون پیشرفت تحصیلی پایه   دهم کاردانشآزمون پیشرفت تحصیلی پایه   دهم کاردانش
آزمون پیشرفت تحصیلی پایه دهم کاردانشtarasad
 
La Calidad Educativa
La Calidad EducativaLa Calidad Educativa
La Calidad EducativaFree TIC
 
Bella Orizaba
Bella OrizabaBella Orizaba
Bella Orizabamafg.46
 
Comunicación Social y periodismo
Comunicación Social y periodismoComunicación Social y periodismo
Comunicación Social y periodismoTania Marcela
 
Religion Y la Astronomia
Religion Y la AstronomiaReligion Y la Astronomia
Religion Y la Astronomiaguest876143
 
Jabon Liquido Con Aroma A Kiwi2
Jabon Liquido Con Aroma A Kiwi2Jabon Liquido Con Aroma A Kiwi2
Jabon Liquido Con Aroma A Kiwi2difercigo
 

En vedette (17)

formatos de imagen
formatos de imagenformatos de imagen
formatos de imagen
 
Estadística General
Estadística GeneralEstadística General
Estadística General
 
Resume_Dinesh
Resume_DineshResume_Dinesh
Resume_Dinesh
 
Iniciando c
Iniciando cIniciando c
Iniciando c
 
Estrategias
EstrategiasEstrategias
Estrategias
 
3Com 3C595-TX-SER
3Com 3C595-TX-SER3Com 3C595-TX-SER
3Com 3C595-TX-SER
 
experimento sólido-líquido
experimento sólido-líquidoexperimento sólido-líquido
experimento sólido-líquido
 
آزمون پیشرفت تحصیلی پایه دهم کاردانش
آزمون پیشرفت تحصیلی پایه   دهم کاردانشآزمون پیشرفت تحصیلی پایه   دهم کاردانش
آزمون پیشرفت تحصیلی پایه دهم کاردانش
 
lecturas
  lecturas   lecturas
lecturas
 
La Calidad Educativa
La Calidad EducativaLa Calidad Educativa
La Calidad Educativa
 
Bella Orizaba
Bella OrizabaBella Orizaba
Bella Orizaba
 
Comunicación Social y periodismo
Comunicación Social y periodismoComunicación Social y periodismo
Comunicación Social y periodismo
 
Secuencia de Windows update
Secuencia de Windows updateSecuencia de Windows update
Secuencia de Windows update
 
Religion Y la Astronomia
Religion Y la AstronomiaReligion Y la Astronomia
Religion Y la Astronomia
 
Monogrfia Cantonal.
Monogrfia Cantonal.Monogrfia Cantonal.
Monogrfia Cantonal.
 
expo
expoexpo
expo
 
Jabon Liquido Con Aroma A Kiwi2
Jabon Liquido Con Aroma A Kiwi2Jabon Liquido Con Aroma A Kiwi2
Jabon Liquido Con Aroma A Kiwi2
 

Similaire à Selfish presentation - ruby internals

PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
A linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares DornellesA linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares DornellesTchelinux
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming LanguageDuda Dornelles
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record.toster
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds LsArrrrCamp
 
Introduction to the Ruby Object Model
Introduction to the Ruby Object ModelIntroduction to the Ruby Object Model
Introduction to the Ruby Object ModelMiki Shiran
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیMohammad Reza Kamalifard
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...scalaconfjp
 
Self, Class and Module
Self, Class and ModuleSelf, Class and Module
Self, Class and ModuleGourav Tiwari
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)RORLAB
 

Similaire à Selfish presentation - ruby internals (20)

PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
A linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares DornellesA linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming Language
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Ruby Classes
Ruby ClassesRuby Classes
Ruby Classes
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds Ls
 
Introduction to the Ruby Object Model
Introduction to the Ruby Object ModelIntroduction to the Ruby Object Model
Introduction to the Ruby Object Model
 
Ruby
RubyRuby
Ruby
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
360|iDev
360|iDev360|iDev
360|iDev
 
Python Metaclasses
Python MetaclassesPython Metaclasses
Python Metaclasses
 
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
 
Self, Class and Module
Self, Class and ModuleSelf, Class and Module
Self, Class and Module
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
Ruby objects
Ruby objectsRuby objects
Ruby objects
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 

Dernier

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 

Dernier (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Selfish presentation - ruby internals

  • 1. module Exlabs class Presentation attr_reader :author, :title, :date def self.ish new(author: 'Wojtek Widenka', title: 'Selfish Presentation') end def initialize(params) @author = params.fetch(:author, 'unknown') @title = params.fetch(:title, 'unknown') @date = params.fetch(:date, Date.today) end end end
  • 2. module Exlabs class Presentation attr_reader :author, :title, :date puts "1: #{self}" def self.ish puts "2: #{self}" new(author: 'Wojtek Widenka', title: 'Selfish Presentation') end def initialize(params = {}) @author = params.fetch(:author, 'unknown') @title = params.fetch(:title, 'unknown') @date = params.fetch(:date, Date.today) puts "3: #{self}" end def foo puts "4: #{self}" end end end
  • 3. module Exlabs class Presentation attr_reader :author, :title, :date puts "1: #{self}t#{self.class}" def self.ish puts "2: #{self}t#{self.class}" new(author: 'Wojtek Widenka', title: 'Selfish Presentation') end def initialize(params = {}) @author = params.fetch(:author, 'unknown') @title = params.fetch(:title, 'unknown') @date = params.fetch(:date, Date.today) puts "3: #{self}t#{self.class}" end def foo puts "4: #{self}t#{self.class}" end end end # enter the text from left side 1: Exlabs::Presentation Class => :foo > object = Exlabs::Presentation.ish 2: Exlabs::Presentation Class 3: #<Exlabs::Presentation:0x007f8fa9eac028> Exlabs::Presentation => #<Exlabs::Presentation:0x007f8fa9eac028 @author="Wojtek Widenka", @title="Selfish Presentation", @date=#<Date: 2016-10-26 ((2457688j,0s,0n),+0s,2299161j)>> > object.foo 4: #<Exlabs::Presentation:0x007f8fa9eac028> Exlabs::Presentation => nil
  • 4. SystemStackError: stack level too deep def self.h @h = 'st' puts h end module Exlabs class Examples -> end end def self.a puts a end def self.b puts self.b end st => nil def self.c c = 'st' puts c end def self.d d = 'st' puts self.d end def self.e self.e = 'st' puts e end def self.f self.f = 'st' puts self.f end def self.g @g = 'st' puts @g end > Exlabs::Examples.a NoMethodError: undefined method `e=' for Exlabs::Examples:Class def self.i @i = 'st' puts self.i end
  • 5. SystemStackError: stack level too deep def q @q = 'st' puts q end module Exlabs class Examples -> end end def j puts j end def k puts self.k end st => nil def l l = 'st' puts l end def m m = 'st' puts self.m end def n self.n = 'st' puts n end def o self.o = 'st' puts self.o end def p @p = 'st' puts @p end > Exlabs::Examples.new.j NoMethodError: undefined method `n=' for #<Exlabs::Examples:0x007f8130af82d8> def r @r = 'st' puts self.r end
  • 6. SystemStackError: stack level too deep def self.h @h = 'st' puts h end module Exlabs class Examples -> end end def self.a puts a end def self.b puts self.b end st => nil def self.c c = 'st' puts c end def self.d d = 'st' puts self.d end def self.e self.e = 'st' puts e end def self.f self.f = 'st' puts self.f end def self.g @g = 'st' puts @g end > Exlabs::Examples.a NoMethodError: undefined method `e=' for Exlabs::Examples:Class def self.i @i = 'st' puts self.i end
  • 7. SystemStackError: stack level too deep def q @q = 'st' puts q end module Exlabs class Examples -> end end def j puts j end def k puts self.k end st => nil def l l = 'st' puts l end def m m = 'st' puts self.m end def n self.n = 'st' puts n end def o self.o = 'st' puts self.o end def p @p = 'st' puts @p end > Exlabs::Examples.new.j NoMethodError: undefined method `n=' for #<Exlabs::Examples:0x007f8130af82d8> def r @r = 'st' puts self.r end
  • 8. module Exlabs class Presentation attr_reader :author, :title, :date puts "1: #{self}t#{self.class}" def self.ish puts "2: #{self}t#{self.class}" new(author: 'Wojtek Widenka', title: 'Selfish Presentation') end class << self puts "5: #{self}t#{self.class}" def bar puts "6: #{self}t#{self.class}" end def self.foobar puts "7: #{self}t#{self.class}" end end def initialize(params = {}) @author = params.fetch(:author, 'unknown') @title = params.fetch(:title, 'unknown') @date = params.fetch(:date, Date.today) puts "3: #{self}t#{self.class}" end def foo puts "4: #{self}t#{self.class}" end end end # enter the text from left side 1: Exlabs::Presentation Class 5: #<Class:Exlabs::Presentation> Class => :foo > object = Exlabs::Presentation.ish 2: Exlabs::PresentationClass 3: #<Exlabs::Presentation:0x007fce5514b218> Exlabs::Presentation => #<Exlabs::Presentation:0x007fce5514b218 @author=[…]> > object.foo 4: #<Exlabs::Presentation:0x007fce5514b218> Exlabs::Presentation => nil > object.bar NoMethodError: undefined method `bar' for #<Exlabs::Presentation:0x007fce5514b218> > Exlabs::Presentation.bar 6: Exlabs::Presentation Class => nil > object.foobar NoMethodError: undefined method `foobar' for #<Exlabs::Presentation:0x007fce5514b218> > Exlabs::Presentation.foobar NoMethodError: undefined method `foobar' for Exlabs::Presentation:Class > Exlabs::Presentation.singleton_class.foobar 7: #<Class:Exlabs::Presentation> Class => nil
  • 9. module Exlabs class Presentation attr_reader :author, :title, :date puts "1: #{self}t#{self.class}" def self.ish puts "2: #{self}t#{self.class}" new(author: 'Wojtek Widenka', title: 'Selfish Presentation') end class << self puts "5: #{self}t#{self.class}" def bar puts "6: #{self}t#{self.class}" end def self.foobar puts "7: #{self}t#{self.class}" end end def initialize(params = {}) @author = params.fetch(:author, 'unknown') @title = params.fetch(:title, 'unknown') @date = params.fetch(:date, Date.today) puts "3: #{self}t#{self.class}" end def foo puts "4: #{self}t#{self.class}" end end end module Exlabs class Stranger class << self puts "8: #{self}t#{self.class}" def bar puts "9: #{self}t#{self.class}" end private def private_method puts 'Just a text' end end class << Presentation puts "10: #{self}t#{self.class}" def bar puts "11: #{self}t#{self.class}" end end end end # enter the text from left side 8: #<Class:Exlabs::Stranger> Class 10: #<Class:Exlabs::Presentation> Class => :bar > Exlabs::Stranger.bar 9: Exlabs::Stranger Class => nil > Exlabs::Stranger.private_method NoMethodError: private method `private_method' called for Exlabs::Stranger:Class > Exlabs::Presentation.bar 11: Exlabs::Presentation Class => nil
  • 10. str1 = 'String 1' str2 = 'String 2' class << String def foo puts 'foo called' puts self end end class << str1 def bar puts 'bar called' puts self end end > str1.foo NoMethodError: undefined method `foo' for "String 1":String > String.foo foo called String => nil > str1.bar bar called String 1 => nil > str2.bar NoMethodError: undefined method `bar' for "String 2":String > String.singleton_class.method_defined? :bar => false > str1.singleton_class.method_defined? :bar => true > str2.singleton_class.method_defined? :bar => false
  • 11. str1 = 'String 1' str2 = 'String 2' class << String def foo puts 'foo called' puts self end end class << str1 def bar puts 'bar called' puts self end end > str1.foo NoMethodError: undefined method `foo' for "String 1":String > String.foo foo called String => nil > str1.bar bar called String 1 => nil > str2.bar NoMethodError: undefined method `bar' for "String 2":String > String.singleton_class.method_defined? :bar => false > str1.singleton_class.method_defined? :bar => true > str2.singleton_class.method_defined? :bar => false
  • 12. ▸ ruby is tricky ▸ in ruby everything is an object ▸ from ruby implementation point of view Class is slightly different than Object struct RObject { struct RBasic basic; union { struct { uint32_t numiv; VALUE *ivptr; void *iv_index_tbl; } heap; VALUE ary[ROBJECT_EMBED_LEN_MAX]; } as; }; struct RBasic { VALUE flags; const VALUE klass; } struct RClass { struct RBasic basic; VALUE super; rb_classext_t *ptr; struct rb_id_table *m_tbl; }; ▸ classes contains methods while objects variables (this is confusing, not sure if can explain)
  • 13. ▸ when we implementing new class class NewClass def new_method end end ▸ we are creating new instance of Class (we can use instead Class.new syntax) ▸ There is also constructed singleton class (eigenclass, metaclass) in which methods are stored ▸ Since it is singleton it cannot be duplicated and is connected always with one object ▸ ruby is tricky, metaclass is transparent, so calling #class on object will ommit it
  • 14.
  • 15.
  • 16. "Nathan".is_a?(BasicObject) # => true "Nathan" is an object. "Nathan".class #=> String "Nathan" is an instance of the String class. "Nathan".is_a?(Class) #=> false "Nathan" is not a class. "Nathan".superclass # NoMethodError "Nathan" has no superclass, because "Nathan" is not a class. String.is_a?(BasicObject) #=> true String is an object. String.class #=> Class String is an instance of the Class class. String.superclass #=> Object String's superclass is Object. Object.is_a?(BasicObject) #=> true Object is an object. Object.class #=> Class Object is an instance of the Class class. Object.superclass #=> BasicObject Object's superclass is BasicObject. BasicObject.is_a?(BasicObject) #=> true BasicObject is an object. BasicObject.class #=> Class BasicObject is an instance of the Class class BasicObject.superclass #=> nil BasicObject's superclass is nil. nil.is_a?(BasicObject) #=> true nil is an object. nil.class #=> NilClass nil is an instance of the NilClass class nil.superclass # NoMethodError nil has no superclass, because it is not a class.
  • 17. Class.is_a?(BasicObject) #=> true Class is an object. Class.class #=> Class Class is an instance of the Class class. # this is probably the most important part. Class.superclass #=> Module Class's superclass is Module # 2nd most important part Module.is_a?(BasicObject) #=> true Module is an object Module.class #=> Class Module is an instance of the Class class. # 3rd Module.superclass #=> Object Module's superclass is Object # 4th Object.is_a?(BasicObject) #=> true Object is an object. Object.class #=> Class Object is an instance of the Class class. Object.superclass #=> BasicObject Object's superclass is BasicObject. BasicObject.is_a?(BasicObject) #=> true BasicObject is an object. BasicObject.class #=> Class BasicObject is an instance of the Class class BasicObject.superclass #=> nil BasicObject's superclass is nil. nil.is_a?(BasicObject) #=> true nil is an object. nil.class #=> NilClass nil is an instance of the NilClass class nil.superclass # NoMethodError nil has no superclass, because it is not a class.