smart_methods helps to define class and instance methods using pretty DSL
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
smart_methods.gemspec

README.md

smart_methods

smart_methods helps to define class and instance methods using pretty DSL.

Build Status Gem Version Dependency Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'smart_methods'

Usage

Working with class methods:

class Source
  extend SmartMethods
  smart_methods :status, :type

  self.status 'undefined'
  self.type 'undefined'
end

class Sms < Source
  self.type 'sms'
end

class Phone < Source
end

Phone.type = 'phone'

Phone.type
# => 'phone'

Sms.type
# => 'sms'

Phone.status
# => "undefined"

Working with instance methods:

class Source
  extend SmartMethods
  smart_methods :status, :type

  status { "new_" + type.to_s }
end

Source.new.type
# => nil

Source.new.status
# => 'new_'

class Sms < Source
  type { 'sms' }
end

Sms.new.type
# => 'sms'

Sms.new.status
# => 'new_sms'

class Phone < Sms
  type { 'phone' }
end

Phone.new.status
# => 'new_phone'

class Email < Sms
end

email = Email.new
email.type = 'email'

email.type
# => 'email'

email.status
# => 'new_email'

Thanks

Sponsored by [Evil Martians]. [Evil Martians]: http://evilmartians.com/