- Implements ~90% of Ruby functionality with some bugs
- Can be used to create OS X desktop applications
- Integrates with XCode
- Uses the Obj-C GC (deprecated)
- Fix known Ruby compatibility bugs
require 'benchmark' | |
class TestBench | |
VALUES = { first: "A", | |
second: "B", | |
third: "C", | |
fourth: "D" } | |
def check_with_map(val) | |
VALUES.fetch(val, "not found") |
Before abuse of C: | |
18.902s | |
18.798s | |
18.789s | |
18.921s | |
18.992s | |
======= | |
Avg: 18.880s |
+ (NSArray *)testInvocations { | |
unsigned int methodCount; | |
Method *methods = class_copyMethodList(self, &methodCount); | |
assert(methodCount); | |
Method method; | |
SEL methodName; | |
NSMethodSignature *methodSig; | |
NSMutableArray *invocations = [[NSMutableArray alloc] init]; |
#include <stdio.h> | |
void method(char* first, char* second, char* third) | |
{ | |
printf("method arguments - first: %s, second: %s, third: %s\n", first, second, third); | |
return; | |
} | |
void wrapped_method(char* first, char* second, char* third); | |
#define method(first, second, third) wrapped_method((second), (third), (first)) |
def process(input) | |
commands = { | |
'q' => -> { puts 'Goodbye' }, | |
'tweet' => -> { puts 'tweeting' }, | |
'dm' => -> { puts 'direct messaging' }, | |
'help' => -> { puts 'helping' } | |
} | |
commands.fetch(input, -> {}).call() | |
end |
def munger(&block) | |
block.binding.eval('b = rand(99)') | |
end | |
def doit | |
a = 1 | |
b = 2 | |
munger do; end | |
puts "a + b = #{a + b}" | |
end |
class FunkyStringComp | |
def to_str | |
raise "This is some crazy shit..." | |
end | |
def <=>(oth) | |
3.0 | |
end | |
end |
class Greater | |
def <=>(other) | |
1 | |
end | |
end | |
g = Greater.new | |
t = Time.now | |
s = "test" | |
i = 101 |
### | |
# | |
# This is a dirty, dirty trick to write tests that test `require`: | |
# | |
module RequireMock | |
REQUIRE_SENTINEL = [] | |
def require(lib) | |
REQUIRE_SENTINEL << lib | |
super |