This file contains hidden or 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 Child | |
| @@name = "baby" | |
| def name | |
| return @@name | |
| end | |
| end | |
| class OtherChild | |
| @@name = "baby" |
This file contains hidden or 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
| def yum(arg) | |
| sleep 10 | |
| puts arg | |
| end | |
| def async(arg, callback) | |
| thr = Thread.new { eval(callback.call(arg)) } | |
| thr | |
| end |
This file contains hidden or 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 'rubygems' | |
| require 'httparty' | |
| def async(arg,callback) | |
| Thread.new { | |
| sleep 10 | |
| resp = HTTParty.get(arg) | |
| callback.call(resp) | |
| } | |
| end |
This file contains hidden or 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 = { | |
| :addOne => lambda {|x| x+1}, | |
| :face => "happy" | |
| } | |
| puts obj[:addOne].call(5) #=> 6 | |
| puts obj[:face] #=> happy |
This file contains hidden or 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 '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 |
This file contains hidden or 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 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 |
This file contains hidden or 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 Animal | |
| def noise(sound) | |
| yield(sound) | |
| end | |
| end | |
| class Cow < Animal | |
| def moo | |
| noise("moo") | |
| end |
This file contains hidden or 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
| yummy = lambda {|number| number + 5} | |
| foo = [1,2,3,4] | |
| puts foo.each(&yummy) #=> 1,2,3,4 WTF? |
This file contains hidden or 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 '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) | |
| } | |
This file contains hidden or 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 '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) | |
| } | |