Module: FSM::Util::Methods
Instance Method Summary collapse
- #bcall(b, *a) ⇒ Object
- #const(*a) ⇒ Object
- #ex(&b) ⇒ Object
- #icall(b, *a) ⇒ Object
- #initialize(*a, &b) ⇒ Object
- #instance_exec(*a, &b) ⇒ Object
- #klass ⇒ Object
- #mcall(obj, msg, *a) ⇒ Object
- #sh(&b) ⇒ Object
- #singleton_class(&b) ⇒ Object
- #string(*list) ⇒ Object
- #string_list(*list) ⇒ Object
- #system(*a, &b) ⇒ Object
Instance Method Details
#bcall(b, *a) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fsm-0.0.0/util.rb', line 51 def bcall b, *a arity = b.arity if arity > 0 a = a[0...arity] elsif arity < 0 arity = arity.abs a = a[0...arity] + (a[arity..-1] || []) else a.clear end b.call *a end |
#const(*a) ⇒ Object
35 36 37 |
# File 'lib/fsm-0.0.0/util.rb', line 35 def const(*a) Const.new(*a) end |
#ex(&b) ⇒ Object
114 |
# File 'lib/fsm-0.0.0/util.rb', line 114 def ex(&b) synchronize(:EX, &b) end |
#icall(b, *a) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fsm-0.0.0/util.rb', line 69 def icall b, *a arity = b.arity if arity > 0 a = a[0...arity] elsif arity < 0 arity = arity.abs a = a[0...arity] + (a[arity..-1] || []) else a.clear end instance_exec *a, &b end |
#initialize(*a, &b) ⇒ Object
117 118 119 |
# File 'lib/fsm-0.0.0/util.rb', line 117 def initialize(*a, &b) sync_initialize end |
#instance_exec(*a, &b) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fsm-0.0.0/util.rb', line 91 def instance_exec *a, &b m, n = nil, -1 loop{ m = "__instance_exec_#{ Thread.current.object_id.abs }_#{ n += 1 }__" break unless respond_to? m } singleton_class{ define_method m, &b } send m, *a ensure singleton_class{ undef_method m } end |
#klass ⇒ Object
47 48 49 |
# File 'lib/fsm-0.0.0/util.rb', line 47 def klass self.class end |
#mcall(obj, msg, *a) ⇒ Object
64 65 66 67 |
# File 'lib/fsm-0.0.0/util.rb', line 64 def mcall obj, msg, *a m = obj.method(msg).to_proc bcall m, *a end |
#sh(&b) ⇒ Object
113 |
# File 'lib/fsm-0.0.0/util.rb', line 113 def sh(&b) synchronize(:SH, &b) end |
#singleton_class(&b) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/fsm-0.0.0/util.rb', line 105 def singleton_class &b sc = class << self; self; end sc.module_eval &b if b sc end |
#string(*list) ⇒ Object
43 44 45 |
# File 'lib/fsm-0.0.0/util.rb', line 43 def string *list string_list(*list).first end |
#string_list(*list) ⇒ Object
39 40 41 |
# File 'lib/fsm-0.0.0/util.rb', line 39 def string_list *list list.flatten.map{|elem| elem.to_s} end |
#system(*a, &b) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/fsm-0.0.0/util.rb', line 82 def system *a, &b verbose = $VERBOSE $VERBOSE = nil ::Kernel.system *a, &b ensure $VERBOSE = verbose end |