SlideShare a Scribd company logo
1 of 40
Ruby Metaprogramming
About me ,[object Object],[object Object],[object Object],[object Object]
Metaprogramming ,[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object]
Part 1. Object, Class and Module ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Object Introspection
Metaprogramming Ruby p.38 Objects of the same class share methods, but they don’t share instance variables.
Classes ,[object Object],[object Object]
Method Lookup ,[object Object],obj @val MyClass my_method() class() Object
Open Class ,[object Object]
Module ,[object Object],[object Object],[object Object],[object Object]
Module obj @val Myclass my_method (M) m_method Object class
Singleton Method
Class Method are Singleton Method
Metaclass ,[object Object],[object Object],[object Object],obj @val Myclass my_method (M) m_method Object class
Metaclass
Define Class Methods
What about module?
Method Lookup Review obj @val MyClass my_method (M) m_method Object class #obj my_singleton_method #MyClass class_method_1 class_method_2 #(M) m_class_method #Object
Define Methods Dynamically
Calling Method Dynamically
method_missing() ,[object Object],[object Object],[object Object]
Overriding method_missing()
 
Hook methods ,[object Object],[object Object]
Part 2. Block ,[object Object],[object Object],[object Object]
Block
Scope (But don’t do that)
Scope Gates ,[object Object],[object Object],[object Object]
Proc Object
The & Operator ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The & Operator
Part 3. Eval* family ,[object Object],[object Object],[object Object]
Kernel#eval() ,[object Object],[object Object]
The troble with eval() ,[object Object],[object Object],[object Object],[object Object]
Object#instance_eval
Module#class_eval(module_eval)
Classes themselves are nothing but  objects .
Thanks
Q&A

More Related Content

What's hot

Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
backdoor
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
Jan Niño Acierto
 

What's hot (20)

Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for Java
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic Concepts
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Class1
Class1Class1
Class1
 

Viewers also liked

把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
Wei Jen Lu
 
BDD for Rails Legacy Code
BDD for Rails Legacy CodeBDD for Rails Legacy Code
BDD for Rails Legacy Code
Wei Jen Lu
 
Mock Aren't Stub 讀後心得
Mock Aren't Stub 讀後心得Mock Aren't Stub 讀後心得
Mock Aren't Stub 讀後心得
Wei Jen Lu
 
SESC / Biennial by Ilaria Montorsi and Giovanni Saladino
SESC / Biennial by Ilaria Montorsi and Giovanni  SaladinoSESC / Biennial by Ilaria Montorsi and Giovanni  Saladino
SESC / Biennial by Ilaria Montorsi and Giovanni Saladino
vsideris
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Manoj Kumar
 

Viewers also liked (18)

把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
 
BDD for Rails Legacy Code
BDD for Rails Legacy CodeBDD for Rails Legacy Code
BDD for Rails Legacy Code
 
BDD for Ruby
BDD for RubyBDD for Ruby
BDD for Ruby
 
Mock Aren't Stub 讀後心得
Mock Aren't Stub 讀後心得Mock Aren't Stub 讀後心得
Mock Aren't Stub 讀後心得
 
Presentation1
Presentation1Presentation1
Presentation1
 
SESC / Biennial by Ilaria Montorsi and Giovanni Saladino
SESC / Biennial by Ilaria Montorsi and Giovanni  SaladinoSESC / Biennial by Ilaria Montorsi and Giovanni  Saladino
SESC / Biennial by Ilaria Montorsi and Giovanni Saladino
 
Fiberstars Design Presentation 2009
Fiberstars Design Presentation 2009Fiberstars Design Presentation 2009
Fiberstars Design Presentation 2009
 
PME DJ Service Presentation
PME DJ Service PresentationPME DJ Service Presentation
PME DJ Service Presentation
 
Trend Report
Trend ReportTrend Report
Trend Report
 
Metaprogramming With Ruby
Metaprogramming With RubyMetaprogramming With Ruby
Metaprogramming With Ruby
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby Metaprogramming
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Ruby An Introduction
Ruby An IntroductionRuby An Introduction
Ruby An Introduction
 
The Black Magic of Ruby Metaprogramming
The Black Magic of Ruby MetaprogrammingThe Black Magic of Ruby Metaprogramming
The Black Magic of Ruby Metaprogramming
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 

Similar to Ruby Metaprogramming

Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Application package
Application packageApplication package
Application package
JAYAARC
 
Aman kingrubyoo pnew
Aman kingrubyoo pnew Aman kingrubyoo pnew
Aman kingrubyoo pnew
ThoughtWorks
 

Similar to Ruby Metaprogramming (20)

Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Lightning talk
Lightning talkLightning talk
Lightning talk
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Introduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APIIntroduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection API
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 
Ruby OOP: Objects over Classes
Ruby OOP: Objects over ClassesRuby OOP: Objects over Classes
Ruby OOP: Objects over Classes
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance Concepts
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Application package
Application packageApplication package
Application package
 
13 ruby modules
13 ruby modules13 ruby modules
13 ruby modules
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
 
The Ring programming language version 1.3 book - Part 55 of 88
The Ring programming language version 1.3 book - Part 55 of 88The Ring programming language version 1.3 book - Part 55 of 88
The Ring programming language version 1.3 book - Part 55 of 88
 
Aman kingrubyoo pnew
Aman kingrubyoo pnew Aman kingrubyoo pnew
Aman kingrubyoo pnew
 
25 java interview questions
25 java interview questions25 java interview questions
25 java interview questions
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Ruby Metaprogramming