Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kvo-rb

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kvo-rb

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

KVO - Key-Value Observing for Ruby

KVO provides a mechanism that allows objects to be notified of changes to attributes of other objects. If you have used Key-Value Observing in a Mac OS X or iOS app, KVO will feel very familiar.

Installation

Add this line to your application's Gemfile:

gem 'kvo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kvo

Example

class Product
	attr_accessible :name, :price
	
	def initialize(name)
		self.name = name
	end
end

class StockController
	attr_accessible :products
	
	def initialize
		@products = []
	end
	
	def add_product(product)
		product.addObserver(self, :price)
		@products << product
	end
	
	def observeValueForKeyPath(keyPath, object)
		puts "New price for #{object.name}: #{object.send(keyPath)}"
	end		
end

fruit = Product.new('Banana')
stockManager = StockController.new
stockManager.add_product(fruit)
fruit.price = "0.30"
	=> "New price for Banana: 0.30"

License

MIT license

FAQs

Package last updated on 13 Nov 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc