View monkey_in_the_middle.rb
1 2 3 4 5 6 7 8 9 10
class A
def a
1
end
end
 
original_a = A.instance_method(:a)
A.__send__ :define_method, :a do |*args, &block|
original_a.bind(self).call(*args, &block) + 1
end
View Rakefile
1 2 3 4 5 6 7 8 9 10
task default: 'open'
 
desc 'Open the users html page'
task 'open' => 'users.html' do
sh "open -a 'Google Chrome.app' users.html"
end
 
file 'users.html' => 'users.json' do
sh 'ruby build_html.rb'
end
View A.hx
1 2 3 4 5 6 7
// file: zomg/A.hx
package zomg;
class A {
public static function x() {
trace("this is a");
}
}
View f3.rb
1 2 3 4 5
RSpec.describe 'a' do
it('b') { expect(true).to eq true }
it('c') { expect(true).to eq false }
it('d') { raise "omg" }
end
View Readme.md

A small clone of Sinatra

For the purpose of learning.

Run the example app

View autorun.rb
1 2 3 4 5 6 7 8 9 10
require 'rspec/autorun'
gem 'minitest', '~> 5.6' # might work w/ older vers, I didn't check
require 'minitest'
 
class WhateverTest < Minitest::Test
def setup
@setup_value = true
end
 
def test_it_passes
View tree_paths.rb
1 2 3 4 5 6 7 8 9 10
class TreeNode
attr_reader :datum, :children
 
def initialize(datum)
@datum, @children = datum, []
end
def child_for(datum)
@children.find { |child| datum == child.datum }
end
View seeing_the_included_class.rb
1 2 3 4 5 6 7 8 9 10
require 'objspace'
 
class A
# When we include a module, it makes an invisible "included class" (T_ICLASS),
# and places it in the inheritance hierarchy, as the superclass.
# Hence A the inclusion, A no longer has a direct reference to Object,
# it now has a direct reference to the included class
ObjectSpace.reachable_objects_from(self) # => [#<InternalObject:0x007f8cd29343b8 T_CLASS>, "A", Object]
m = Module.new
include m
Something went wrong with that request. Please try again.