Socket
Book a DemoInstallSign in
Socket

decorator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decorator

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

== Decorator

  • http://github.com/pasberth/Decorator

== DESCRIPTION: the Decorator make a decorator like Python.

== Usage

require 'decorator'

または

require 'decorator/only'

require 'decorator' だと Module#decorator だけでなく Module#kwargsable も一緒に使えます。 require 'decorator/only' だと Module#decorator だけがロードされます

普通、このモジュールで使う関数はModule#decoratorのみです。 それはデコレータを作成するデコレータです。デコレータを作る場合は通常これをデコレータとします。 example: class Module decorator def wrap func, *args, &blk puts "wrapped!" proc { func.call *args, &blk }

デコレータの第一引数は必ずMethodです。 この場合のwrapはデコレータとして使用できます。

 class TestClass
   wrap
   def wrapped *args, &blk
     puts "IN!"

もしデコレータに引数を渡した場合、それはすべてデコレータに一緒に渡されます。

 class TestClass
   wrap(*example_args)
   def wrapped *args, &blk
     puts "IN!"

=> ↓のargsにexample_argsが渡される

   def wrap func, *args, &blk
     puts "wrapped!"
     proc { func.call *args, &blk }

デコレータの戻り値がProcである場合、関数はそのProcに置き換えられます。 たとえばこの場合、wrappedはwrap内のprocに置き換えられます。

FAQs

Package last updated on 24 Feb 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

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.