New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ruby_decorators

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ruby_decorators

  • 0.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Ruby Decorators

Ruby method decorators inspired by Python.

I wrote this as a small practice for some ruby meta-programming fun. The implementation is relatively simple, and is thread safe.

There are also these other two implementations:

  • Yehuda Katz's Ruby Decorators
  • Michael Fairley's Method Decorators

Installation

Add this line to your application's Gemfile:

gem 'ruby_decorators'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruby_decorators

Usage

class Hi < RubyDecorator
  def call(this, *args, &blk)
    this.call(*args, &blk).sub('hello', 'hi')
  end
end

class Batman < RubyDecorator
  def call(this, *args, &blk)
    this.call(*args, &blk).sub('world', 'batman')
  end
end

class Catwoman < RubyDecorator
  def initialize(*args)
    @args = args.any? ? args : ['catwoman']
  end

  def call(this, *args, &blk)
    this.call(*args, &blk).sub('world', @args.join(' '))
  end
end

class World
  extend RubyDecorators

  def initialize
    @greeting = 'hello world'
  end

  def hello_world
    @greeting
  end

  +Batman
  def hello_batman
    @greeting
  end

  +Hi
  +Catwoman
  def hello_catwoman
    @greeting
  end

  +Catwoman.new('super', 'catwoman')
  def hello_super_catwoman
    @greeting
  end
end

world = World.new

world.hello_world          # => "hello world"
world.hello_batman         # => "hello batman"
world.hello_catwoman       # => "hi catwoman"
world.hello_super_catwoman # => "hello super catwoman"

License

Copyright (c) 2012 Fred Wu

Licensed under the MIT license.

FAQs

Package last updated on 12 Sep 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