This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def add_accessor(accessor_name) | |
class << self; self; end.class_eval do | |
attr_accessor accessor_name | |
end | |
end | |
end | |
person = Person.new | |
Person.add_accessor :name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def self.create(options = {}) | |
if options[:queue] | |
define_singleton_method :queue do | |
"#{options[:queue].to_sym}" | |
end | |
end | |
self.enqueue(self, options) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def self.create(options = {}) | |
if options[:queue] | |
self.instance_eval do | |
def queue | |
#{options[:queue].to_sym} | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
direc = File.dirname(__FILE__) | |
require "#{direc}/local_eval/version" | |
require 'remix' | |
require 'object2module' | |
module LocalEval | |
module ObjectExtensions | |
@@m = Mutex.new | |
def local_eval(*objs, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extconf.rb | |
require 'mkmf' | |
create_makefile('foo') | |
# foo.h | |
#ifndef __FOO_H_INCLUDED__ | |
#define __FOO_H_INCLUDED__ | |
#include <ruby.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Scope | |
module ScopeMethods | |
def helpers(&block) | |
self.instance_eval(&block) | |
block.call | |
puts "self inside helpers #{self}" | |
end | |
end | |
def scope(path, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostQuery < Query | |
@@clauses = [:columns, :operations, :order] | |
def initialize(target_object) | |
super(target_object, @@clauses) | |
@clauses.each do |c| | |
class << self; self; end.define_method(c) { self[c] } | |
end | |
NewerOlder