module RustyKey
Constants
- VERSION
Public Instance Methods
Module(&b)
click to toggle source
# File lib/rusty_key/definition.rb, line 42 def Module(&b) # get context in which we're trying to define our module context = binding.of_caller(1).eval('self.class') # does a module (not a class!) with this name already exist? if context.const_defined?(self) && !context.const_get(self).is_a?(Class) && context.const_get(self).is_a?(Module) # a module with this name does exist! we don't want to just replace it, # so let's get to monkey patching. context.const_get(self).module_eval(&b) else # there's no module with this name. there might be another constant, # but who cares? TODO: care context.const_set(self, Module.new(&b)) end nil end
Also aliased as: module, module
alias(original)
click to toggle source
# File lib/rusty_key/definition.rb, line 8 def alias(original) binding.of_caller(1).eval("alias #{self} #{original}") end
and() { || ... }
click to toggle source
# File lib/rusty_key/boolean.rb, line 3 def and raise ArgumentError("Object#and requires a block") unless block_given? self && yield end
case()
click to toggle source
# File lib/rusty_key/case.rb, line 3 def case Case.new(self) end
class(&b)
click to toggle source
# File lib/rusty_key/definition.rb, line 21 def class(&b) return _class unless b # get context in which we're trying to define our class context = binding.of_caller(1).eval('self.class') # does a class with this name already exist? if context.const_defined?(self) && context.const_get(self).is_a?(Class) # a class with this name does exist! we don't want to just replace it, # so let's get to monkey patching. context.const_get(self).class_eval(&b) else # there's no class with this name. there might be another constant, # but who cares? TODO: care context.const_set(self, Class.new(&b)) end nil end
def(&b)
click to toggle source
# File lib/rusty_key/definition.rb, line 3 def def(&b) binding.of_caller(1).eval('self').send(:define_method, self, b || -> {}) self end
extend()
click to toggle source
# File lib/rusty_key/definition.rb, line 16 def extend binding.of_caller(1).eval("extend #{self}") end
Also aliased as: _extend
if(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 13 def if(condition) -> { self }.if(condition) end
if!(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 21 def if!(condition) self.if(condition).call end
include()
click to toggle source
# File lib/rusty_key/definition.rb, line 12 def include binding.of_caller(1).eval("include #{self}") end
Also aliased as: _include
or() { || ... }
click to toggle source
# File lib/rusty_key/boolean.rb, line 8 def or raise ArgumentError("Object#or requires a block") unless block_given? self || yield end
raise()
click to toggle source
# File lib/rusty_key/exception.rb, line 5 def raise id = self.object_id binding.of_caller(1).eval("raise ObjectSpace._id2ref(#{id})") end
rescue(*types, &handler)
click to toggle source
# File lib/rusty_key/exception.rb, line 18 def rescue(*types, &handler) RescuedProc.new(self, *types, &handler) end
return()
click to toggle source
# File lib/rusty_key/misc.rb, line 3 def return id = self.object_id binding.of_caller(1).eval("return ObjectSpace._id2ref(#{id})") end
return_if(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 29 def return_if(condition) if condition result = self.if!(condition) id = result.object_id binding.of_caller(1).eval("return ObjectSpace._id2ref(#{id})") end end
return_unless(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 37 def return_unless(condition) unless condition result = self.unless!(condition) id = result.object_id binding.of_caller(1).eval("return ObjectSpace._id2ref(#{id})") end end
unless(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 17 def unless(condition) -> { self }.unless(condition) end
unless!(condition)
click to toggle source
# File lib/rusty_key/boolean.rb, line 25 def unless!(condition) self.unless(condition).call end
yield()
click to toggle source
# File lib/rusty_key/misc.rb, line 8 def yield b = binding.of_caller(1) # this is kinda hacky, but it is fun if b.local_variables.include? :block b.eval("block.call(#{self})") else b.eval("yield #{self}") end end