Last active
August 29, 2015 14:19
-
-
Save thejsj/86a1156580f916a21c2b to your computer and use it in GitHub Desktop.
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
var obj = { | |
if: function (condition, trueStatement, falseStatement) { | |
if (condition) return trueStatement; | |
return falseStatment; | |
}, | |
in: function () { | |
console.log('This is an `in` method'); | |
}, | |
arguments: function () { | |
console.log('This is an `arguments` method'); | |
}, | |
int: function () { | |
console.log('This is an `int` method'); | |
} | |
}; | |
obj.if(true, true, false); | |
obj.arguments(); | |
obj.in(); | |
obj.int(); |
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
# Thid doesn't work... | |
# class SampleClass(): | |
# def if(self, condition, true_statement, false_statement): | |
# if (condition) return true_statement | |
# return false_statement | |
# sample = SampleClass() | |
# print sample.if(True, True, False) | |
class SampleClass(): | |
def __init__(self): | |
self.data = {} | |
self['if'] = self.create_if_function() | |
def create_if_function(self): | |
def function(self, condition, true_statement, false_statement): | |
if (condition) return true_statement | |
return false_statement | |
return function | |
def __setitem__(self, key, item): | |
self.data[key] = item | |
def __getitem__(self, key): | |
return self.data[key] | |
sample = SampleClass() | |
sample['if']() |
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 SampleClass | |
def if(condition, true_statement, false_statement) | |
if condition | |
return true_statement | |
false_statement | |
end | |
end | |
sample = SampleClass.new() | |
puts sample.if(true, true, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment