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
### Keybase proof | |
I hereby claim: | |
* I am p886 on github. | |
* I am p886 (https://keybase.io/p886) on keybase. | |
* I have a public key whose fingerprint is AB19 9923 F1B6 F633 4756 B21A 2DBF 53C2 E30E D27C | |
To claim this, I am signing this object: |
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
package main | |
import "fmt" | |
// Explanation: | |
// changeIt() takes as argument a pointer to a thing | |
// in line 14 we create such a pointer and pass it to changeIt(). | |
// Hadn't we used a pointer but instead passed thing *normally*, | |
// we would not have been able to observe the change | |
// from "yolo" to "roflmao" in main |
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
def say(a_proc_obj) | |
a_proc_obj.call | |
end | |
def tell | |
yield | |
end | |
a_lambda = -> { puts "there you go" } |
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
# Anonymous Class for quickly building Fake Objects | |
# advantage over Struct: doesn't even need a single argument | |
# (Struct.new accepts 1+ arguments, this 0) | |
thing = Class.new do | |
def name | |
"helloooo!!" | |
end | |
end.new # <-- immediately creating an instance of the anoymous class |
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
# this: | |
person = Struct.new(:name, :age, :human) | |
# …is functionally equivalent to this: | |
class Person | |
attr_accessor :name, :age, :human | |
def initialize name, age, human | |
@name = name | |
@age = age | |
@human = human |
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
lamb = -> do | |
a = 2 | |
b = 0 | |
puts "lamb #{b}" | |
lamb = -> do | |
puts a | |
b += 1 | |
puts "lamb #{b}" | |
lamb = -> do | |
puts a |