Socket
Book a DemoInstallSign in
Socket

instance_property

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instance_property

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

InstanceProperty

Instance property for Ruby

Installation

Add this line to your application's Gemfile:

gem 'instance_property'

And then execute:

$ bundle

Or install it yourself as:

$ gem install instance_property

Usage

reqiure 'instance_property'

class MyClass
  extend InstanceProperty
end

# or

class Module
  include InstanceProperty
end

Module InstanceProperty has two methods ('property' and 'properties').

'property' is a method such as 'attr_accessor'.

class MyClass
  extend InstanceProperty

  property :foo1
  property :foo2, 20			# with initial value
  property(:foo3) { 30 }		# with initial value (given as the block)
end

obj = MyClass.new

p obj.foo1			#=> nil
p obj.foo2			#=> 20
p obj.foo3			#=> 30

obj.foo1 10
p obj.foo1          #=> 10
class MyClass
  extend InstanceProperty

  property :foo, 100
  property(:bar) { foo + 20 }
  property(:baz) { bar +  3 }
end

obj1 = MyClass.new
p obj1.baz		#=> 123		# (foo=100) + (bar=20) + 3

obj2 = MyClass.new
obj2.foo = 900
p obj2.baz		#=> 923		# (foo=900) + (bar=20) + 3

obj3 = MyClass.new
obj3.bar = 90
p obj3.baz		#=> 93		# (bar=90) + 3

class MyClass
  extend InstanceProperty

  properties :foo1, :foo2
  properties(:foo3, :foo4) { 400 }
end

# same as

class MyClass
  extend InstanceProperty

  property :foo1
  property :foo2
  property(:foo3) { 400 }
  property(:foo4) { 400 }
end

Contributing

  • Fork it ( https://github.com/[my-github-username]/instance_property/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 27 Dec 2014

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.