Last active
August 29, 2015 14:21
-
-
Save salvianoo/ed80dd579c3a32659c66 to your computer and use it in GitHub Desktop.
fun with procs
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 'ostruct' | |
Stack = (->() { | |
struct = OpenStruct.new | |
_data = [] | |
struct.push = ->(thing) { | |
_data << thing | |
} | |
struct.pop = ->() { | |
_data.pop | |
} | |
struct.data = ->() { | |
_data | |
} | |
struct | |
}).call | |
Stack.push.call 1 | |
Stack.push.call 2 | |
Stack.push.call 3 | |
puts Stack.data.call.inspect | |
Stack.pop.call | |
puts Stack.data.call.inspect |
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
var Stack = (function() { | |
var stack = {} | |
, _data = []; | |
var stack.push = function(thing) { | |
_data.push(thing); | |
}; | |
var stack.pop = function() { | |
return _data.pop(); | |
}; | |
var stack.data = function() { | |
return _data; | |
}; | |
return stack; | |
}()); | |
Stack.push(1); | |
Stack.push(2); | |
Stack.push(3); | |
console.log(Stack.data()); | |
Stack.pop(); | |
console.log(Stack.data()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment