An Invariable bundles a number of read-only attributes. It can be used like a Hash as well as an Array. It supports subclassing and pattern matching.

An Invariable can be created explicitly as a Class like a Struct. Or existing classes can easily be extended to an Invariable.


require 'invariable'

class Person
  include Invariable
  attributes :name, :last_name
  attribute address:, :zip, :street)

  def full_name
    "#{name} #{last_name}"
john = 'John', last_name: 'Doe')
john.full_name #=> "John Doe" #=> nil
john = john.update(
  address: { street: '123 Main St', city: 'Anytown', zip: '45678' }
john.dig(:address, :city) #=> "Anytown"

For more samples see the samples dir


Use Bundler to use TCPClient in your own project:

Add to your Gemfile:

gem 'invariable'

and install it by running Bundler:


To install the gem globally use:

gem install invariable

After that you need only a single line of code in your project to have all tools on board:

require 'invariable'