Giter Club home page Giter Club logo

metapreso's Introduction

BETTER LIVING THROUGH META-PROGRAMMING

These are the slides and example files used for the MDC 2011 presentation I did on metaprogramming.

Most of the material of interest is in the .rb files:

Open classes:

  • Adding new methods to an existing class: see ord.rb (the String class)
  • Overriding existing methods: see apples_and_oranges.rb (we override ==)

Hook methods:

  • inherited and at_exit in testy_testy.rb and some_test.rb
  • included example in apples_and_oranges.rb
  • a bit about the included idiom as used in rails acts_as style plugins, in acts_as_something.rb

Method missing:

  • friendlier errors and delegation: person_permissions.rb
  • flexible apis: see the Array class in ord.rb
  • more on flexible apis: look up how ActiveRecord handles methods like find_by_name_and_email_and_age, etc.

DSLs

Ruby macros:

  • something that works like attr_accessor, but accepts a block with an initial value for the attribute: object_accessor.rb

That's about it. Take a look through the slides, try to run and understand the example files, and play around with classes and objects in irb.

Also in the repo is Paul Cantrell's closures-in-ruby.rb, which I never got around to talking about in the presentation, but which is really interesting, and which you'll probably enjoy if you like this sort of thing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.