Skip to content

Instantly share code, notes, and snippets.

View hackervera's full-sized avatar
😻

Veronika Tyler hackervera

😻
View GitHub Profile
class Child
@@name = "baby"
def name
return @@name
end
end
class OtherChild
@@name = "baby"
def yum(arg)
sleep 10
puts arg
end
def async(arg, callback)
thr = Thread.new { eval(callback.call(arg)) }
thr
end
require 'rubygems'
require 'httparty'
def async(arg,callback)
Thread.new {
sleep 10
resp = HTTParty.get(arg)
callback.call(resp)
}
end
obj = {
:addOne => lambda {|x| x+1},
:face => "happy"
}
puts obj[:addOne].call(5) #=> 6
puts obj[:face] #=> happy
require 'rubygems'
require 'httparty'
require 'json'
obj = {
:addOne => lambda {|x| x+1},
:face => "happy",
:getSite => lambda {|url| HTTParty.get(url)},
:parseJson => lambda {|url| JSON.parse(HTTParty.get(url))}
}
puts obj[:addOne].call(5) #=> 5
class Main
def self.higherOrder(proc_in)
return proc { |arg| arg + proc_in[5] }
end
end
foo = proc {|arg| arg + 1}
puts Main::higherOrder(foo)[3] #=> 9
class Animal
def noise(sound)
yield(sound)
end
end
class Cow < Animal
def moo
noise("moo")
end
yummy = lambda {|number| number + 5}
foo = [1,2,3,4]
puts foo.each(&yummy) #=> 1,2,3,4 WTF?
require 'rubygems'
require 'httparty'
def async(arg,wait,callback)
Thread.new {
sleep wait
resp = HTTParty.get(arg)
(wait == 10) ? callback.error("Failed to get resource") : callback.success(resp)
}
require 'rubygems'
require 'httparty'
def async(arg,wait,callback)
Thread.new {
sleep wait
resp = HTTParty.get(arg)
(wait == 10) ? callback.error("Failed to get resource") : callback.success(resp)
}