Sha256: 01618e51f32917228993dbf1e72c5509041ea3cde8fc4a79b3d29fd8e65527f2

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

=begin
"my notification".observe(obj, :notified)
  # => NSNotificationCenter.defaultCenter.addObserver(obj, selector::'notified:', name:"my notification", object: nil)
"my notification".observe(obj) { |notification| puts notification }
  # => NSNotificationCenter.defaultCenter.addObserver(obj, selector::'__sugarcube_notified__:', name:"my notification", object: Proc.new { |notification| puts notification })
"my notification".observe { |notification| puts notification }
  # => NSNotificationCenter.defaultCenter.addObserverForName("my notification", object: nil, queue:NSOperationQueue.mainQueue, usingBlock:{ |notification| puts notification })

"my notification".removeObserver(obj)
  # => NSNotificationCenter.defaultCenter.removeObserver(object, name:"my notification", object: nil)
"my notification".removeObserver(obj, obj2)
  # => NSNotificationCenter.defaultCenter.removeObserver(object, name:"my notification", object: obj2)
=end

class String

  def post_notification(object=nil, user_info=nil)
    if user_info and not Hash === user_info
      raise TypeError("Invalid argument #{user_info.class.name} sent to String.post_notification")
    end

    if user_info
      NSNotificationCenter.defaultCenter.postNotificationName(self, object:object, userInfo:user_info)
    else
      NSNotificationCenter.defaultCenter.postNotificationName(self, object:object)
    end
  end

end


class Object
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sugarcube-0.1.5 lib/sugarcube/notifications.rb