Skip to content

Instantly share code, notes, and snippets.

View banister's full-sized avatar
🇳🇱

John Mair banister

🇳🇱
View GitHub Profile
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)
#include <stddef.h>
#include <stdio.h>
typedef struct mystruct {
int x, y;
double f;
char * hello;
} mystruct;
void
@lsegal
lsegal / method_ext.rb
Created December 20, 2010 04:55
Method class extensions to introspect YARD docs
require 'yard'
class Method
def docstring
@yard_cache ||= {}
file = source_location[0]
unless @yard_cache[file]
YARD.parse(file)
@yard_cache[file] = true
end
class Hello; end
Hello.singleton_class.class #=> Class
# So methods on Hello.singleton_class should be first looked up as instance methods on Class right?
class Class
def hello
puts "from Class"
end
# I want this method in ruby-core
def let
yield
end
def fib(i)
let do |n = 1, result = 0|
if i == -1
result
else
# Ruby edge cases
# lambdas can no longer be used with instance_eval in Ruby 1.9.2
l = lambda { puts "hello world"! }
Object.instance_eval(&l) #=> invalid argument. This is due to the fact instance_eval now yields a value (the receiver) in 1.9
# module double inclusion
# module appear multiple times in inheritance chain
# behaviour of constants in class_eval
# Proc.new can create a proc from an implicit block
pry(main)> class SupBurg
pry(main)* def yo
pry(main)* puts 'swede'
pry(main)* end
pry(main)* end
=> nil
pry(main)> hist
0: class SupBurg
1: def yo
2: puts 'swede'
@MyArtChannel
MyArtChannel / development.rb
Created April 25, 2011 20:42
Use Pry as IRB replacement in rails 3 console
# 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
module Helpers
def use_a_helper
puts "test"
end
end
class Pry::CommandContext
include Helpers
end
* Pry::Helpers::Color:
** bold
** colorize
** blue
** bright_black
** brigt_cyan
** bright_green
** brigt_magenta
** bright_purple
** bright_red