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 | |
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
# 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
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
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
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 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
module MyMod | |
# store the variable on the module itself | |
var = "initial value" | |
# first method that accesses the var | |
define_method :get_var do | |
var | |
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
module Helper | |
def helper_method | |
puts "I'm helping" | |
end | |
end | |
class Main | |
include Helper | |
def show |
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
# Add this to the end of your development.rb and add | |
# | |
# gem 'pry' | |
# | |
# to your Gemfile and run bundle to install. | |
silence_warnings do | |
begin | |
require 'pry' | |
IRB = Pry |
OlderNewer