Socket
Book a DemoInstallSign in
Socket

others

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

others

0.1.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

Functions as Objects, in Ruby

DevOps By Rultor.com We recommend RubyMine

rake PDD status Gem Version Test Coverage Yard Docs Hits-of-Code License

Let's say you need an object that consists of a single function:

require 'others'
x = others(foo: 42) do |*args|
  @foo + args[1]
end
assert(x.bar(10) == 52)

You can also do this in a class:

require 'others'
class Foo
  def foo(a)
    a + 1
  end
  others do |*args|
    args[1] + 10
  end
end
x = Foo.new
assert(x.foo(10) == 11)
assert(x.bar(42) == 52)

For example, you can create a decorator that intercepts all method calls and logs them:

logger = others(base: original_object) do |*args, &block|
  puts "Method #{args[0]} called with #{args[1..-1].inspect}"
  @base.__send__(*args, &block)
end

It also supports forwarding blocks:

x = others(foo: 42) do |*args|
  @foo + args.last.call # this is the block, as the last argument
end
puts x.bar { 12 }  # => 54

How to contribute

Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.2+ and Bundler installed. Then:

bundle update
bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.

FAQs

Package last updated on 20 Jun 2025

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.