From 4f775ac5caa35f824b0bcacafa010f6e0709c62d Mon Sep 17 00:00:00 2001 From: Patrick Mahoney Date: Mon, 12 Dec 2011 20:51:06 -0600 Subject: [PATCH] Add backwards compatibility define_singleton_method for Ruby 1.8. --- lib/process_shared.rb | 19 +++++++++++++++++++ lib/process_shared/define_singleton_method.rb | 14 ++++++++++++++ spec/spec_helper.rb | 3 +++ 3 files changed, 36 insertions(+) create mode 100644 lib/process_shared/define_singleton_method.rb diff --git a/lib/process_shared.rb b/lib/process_shared.rb index 717d0ee..6b1e8bb 100644 --- a/lib/process_shared.rb +++ b/lib/process_shared.rb @@ -1,6 +1,25 @@ require 'ffi' +if VERSION =~ /^1.8/ + require 'process_shared/define_singleton_method' + + module ProcessShared + module PSem + extend DefineSingletonMethod + end + + module RT + extend DefineSingletonMethod + end + + module LibC + extend DefineSingletonMethod + end + end +end + require 'process_shared/semaphore' require 'process_shared/bounded_semaphore' require 'process_shared/mutex' require 'process_shared/shared_memory' + diff --git a/lib/process_shared/define_singleton_method.rb b/lib/process_shared/define_singleton_method.rb new file mode 100644 index 0000000..dd45966 --- /dev/null +++ b/lib/process_shared/define_singleton_method.rb @@ -0,0 +1,14 @@ +module ProcessShared + module DefineSingletonMethod + # This method was added in Ruby 1.9.x. Include this module for + # backwards compatibility. + # + # This isn't exactly compatible with the method in 1.9 which can + # take a Proc, Method, or a block. This only accepts a block. + def define_singleton_method(sym, &block) + eigenclass = class << self; self; end + eigenclass.send(:define_method, sym, &block) + end + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b415a70..7ae810f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,11 @@ +require 'rubygems' if VERSION =~ /^1.8/ gem 'minitest' require 'minitest/spec' require 'minitest/autorun' require 'minitest/matchers' +require 'process_shared' + class RangeMatcher def initialize(operator, limit) @operator = operator.to_sym