Project

thaip

0.0
No commit activity in last 3 years
No release in over 3 years
Thaip is a prototype utility. It provides some easy to use structs and enums. See https://github.com/itarato/prototyper.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Ruby Thaip

This is sortof a toolkit to help prototyping things in Ruby.

Enum maker

Enum-like objects with optional instantiation and value enum types.

TypeDef['Color']
  .with('Red')
  .with('Greeen')
  .with('Blue')

color_result = Red
assert(color_result.is_a?(Color))
assert(color_result.is_a?(Red))
assert(Red.is_a?(Color))
assert(Red.is_a?(Red))
refute(Red.is_a?(Yellow))

TypeDef['Discount']
  .with('Percentage', value: Float)
  .with('Bxgy', buy: Integer, get: Integer, value: Float)

b1g1 = Bxgy.new(buy: 1, get: 1, value: 0.25)

# Bxgy.new(buy: 1, get: 1, value: "12") -> raise, value must be Float

Easier structs

User = MakeStruct[:name, :age]
user = User.new(name: 'Steve', age: 12)

class Project < MakeStruct[:name, city: 'London', badges: -> { [] }]
  def branding
    "#{name} - #{city}"
  end
end

project = Project.new(name: 'Bug-repellent')
project.badges << :capital
puts project.branding

project.city = 'New-London'