Skip to content

Instantly share code, notes, and snippets.

@coreypurcell
Created September 16, 2011 00:34
Show Gist options
  • Save coreypurcell/1220885 to your computer and use it in GitHub Desktop.
Save coreypurcell/1220885 to your computer and use it in GitHub Desktop.
attr_accessor :jmessage
def initialize(message=nil, options={})
if message.kind_of? org.jgroups.Message
@jmessage = message
else
@jmessage = org.jgroups.Message.new(options[:destination],
options[:source],
message)
end
end
def self.from_jmessage(jmessage)
self.new.jmessage = jmessage
end
# So other classes call
Message.new(jmessage)
Message.new("Here is my message"
#
Message.from_jmessage(jmessage)
@phiggins
Copy link

Rather than provide so many options, I think I'd pick one way and stick with it, especially if this class is never instantiated by users of the library (do they?). Since you want to wrap the org.jgroups.Message with your Message class, I think I'd make the initializer look like:

def initialize(message=nil, options={})
  @jmessage = org.jgroups.Message.new(
    options[:destination],
    options[:source],
    message)
end

This is not the end-all-be-all solution though, so do what makes sense for your library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment