Meta programming
Upcoming SlideShare
Loading in...5
×
 

Meta programming

on

  • 951 views

 

Statistics

Views

Total Views
951
Views on SlideShare
861
Embed Views
90

Actions

Likes
1
Downloads
6
Comments
0

2 Embeds 90

http://rubylive.fr 68
http://news.humancoders.com 22

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Meta programming Meta programming Presentation Transcript

  • by @antho1404 Meta programming - Reflexive programming
  • "Capacité d'un programme à examiner et  modifier ses objets lors de son exécution"
  • What's an object ? - attributes - methods - parent object - private - protected - public
  • Introspection:  "L’introspection est la capacité pour un objet de s’auto-examiner"
  • Some usefull methods: :methods                         # list of methods defined :public_methods             # list of public methods :private_methods            # list of private methods :protected_methods         # list of protected methods :instance_variables         # list of instance variables :instance_variable_get    # get value of instance variable     
  • Exemple: class A     @loutre     def initialize         @loutre = 23     end     def update_loutre          @loutre += 1      end end a = A . new  # create a new class # get the value of the attribute a.instance_variable_get "@loutre" # => 23 # call the method update_loutre a.method( "update_loutre" ).call # => 24 # get tue value of the attribute a.instance_variable_get "@loutre" # => 24
  • Intercession:  "L'intercession est la capacité pour un objet de s’auto-modifier"
  • :define_method                     # define a new method :remove_method                   # remove a method :instance_variable_set          # change the value of an variable :remove_instance_variable   # remove an instance variable Some usefull methods:
  • class A     # exemple of method which create methods to select an attribute on a class      def select ( table, attribute )                   # define the method for this class using the attribute and table parameters          self.class.send   :define_method , "select_#{attribute}_on_#{table}"   do                           # use the table and transform it into an object              model = table.classify.constantize                           # select all the value of the attributes given in the function name              model.find :all , :select => attribute         end      end end a = A . new                                  # create the class a.select "user", "name"             # call the method which define a new method a.select_name_on_player         # call the new created method Exemple:
  • Meta programming in other languages Python Java Objective-C PHP4 et + C# Ruby
  • http://www.infoq.com/presentations/metaprogramming-ruby http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html http://www.devsource.com/c/a/Languages/An-Exercise-in-Metaprogramming-with-Ruby http://buhrmi.tumblr.com/post/8035284845/embracing-meta-programming-an-rpg-character-stat http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox http://www.vitarara.org/cms/ruby_metaprogamming_declaratively_adding_methods_to_a_class http://ruby-metaprogramming.rubylearning.com/ Some links to continue
  • @antho1404 antho1404 www.quidizz.com @quidizz Quidizz