diff options
| author | jj | 2012-09-26 15:08:54 +0200 |
|---|---|---|
| committer | jj | 2012-09-26 15:08:54 +0200 |
| commit | d975ce513509d12c1f69752270ce65de4f80d7aa (patch) | |
| tree | 2f5c8b6a5289d0ddd82103652fdb7838dbaff3a9 | |
| parent | f628c3732ae62c324c91553333ebd4e51f486090 (diff) | |
| download | dfhack-d975ce513509d12c1f69752270ce65de4f80d7aa.tar.gz dfhack-d975ce513509d12c1f69752270ce65de4f80d7aa.tar.bz2 dfhack-d975ce513509d12c1f69752270ce65de4f80d7aa.tar.xz | |
ruby: add onstatechange_register_once
| -rw-r--r-- | plugins/ruby/ruby.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb index aeae101d..81b73b7c 100644 --- a/plugins/ruby/ruby.rb +++ b/plugins/ruby/ruby.rb @@ -119,6 +119,14 @@ module DFHack @onstatechange_list.delete b end + # same as onstatechange_register, but auto-unregisters if the block returns true + def onstatechange_register_once + handle = onstatechange_register { |st| + onstatechange_unregister(handle) if yield(st) + } + end + + # this method is called by dfhack every 'onstatechange' def onstatechange(newstate) @onstatechange_list ||= [] |
