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
require "evalhook" | |
class MyHandler < EvalHook::HookHandler | |
... | |
end | |
handler = MyHandler.new | |
packet = handler.pack(code) |
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 Package | |
def run | |
class << Object | |
class ::X | |
def foo | |
print "hello world\n" | |
end | |
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
# coding: utf-8 | |
require 'sinatra' | |
set server: 'thin', connections: [] | |
get '/' do | |
halt erb(:login) unless params[:user] | |
erb :chat, locals: { user: params[:user].gsub(/\W/, '') } | |
end | |
get '/stream', provides: 'text/event-stream' do |
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 TestClass | |
def foo(x) | |
@instance_var + $global.to_i | |
print self.method_name, "\n" | |
x**2 | |
end | |
end | |
suite( 1 => 1, 2 => 4, 3 => 9, 4 => 16 ).test( |
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 ErbEngine < Haml::Engine | |
def push_script(text, preserve_script, in_tag = false, preserve_tag = false, | |
escape_html = false, nuke_inner_whitespace = false) | |
push_text "<%= #{text.strip} %>" | |
end | |
def push_silent(text, can_suppress = false) | |
push_text "<% #{text.strip} %>" | |
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 X | |
attr_accessor :a, :b | |
def initialize | |
@a = 0 | |
@b = b | |
end | |
def foo!(a) | |
@a = a |
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
require "set" | |
require "sexp" | |
class Chain | |
def initialize | |
@groups = Hash.new | |
@enabled_groups = Set.new | |
enable :default | |
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
require "method_source" | |
def method_container_for(target, &blk) | |
# create adhoc class under target | |
method_container = Class.new | |
def method_container.method_added(mname) | |
# do whatever you want with methods (e.g. "use the source" ) | |
p instance_method(mname).source | |
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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
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
obj = lambda{ |binding_| | |
Object.new.tap { |retobj| | |
retobj.instance_variable_set(:@binding_,binding_) | |
def retobj.method_missing(m,arg=nil) | |
if m =~ /(.*)=$/ | |
$tmp = arg | |
@binding_.eval("#{$&} = $tmp") | |
else | |
@binding_.eval(m.to_s) |
OlderNewer