Ifrit
Constants
VERSION = "0.1.3"
Macros
render_macros
Renders convertable macros.
These convert macros are designed to provide interface for converting hash to exact type
(e.g. {"asd" => "asd"} of String | Int64 => Float32 | Symbol | String to String => String).
Adds next macros:
%typed_hash- converts given hash literal to one with given key type (key) and value type (types); without cycles;%sym_hash_cast- is a shortcut for%typed_hashfor symbol keys;%str_hash_cast- is a shortcut for%typed_hashfor string keys;%typed_hash_cast- converts given variable or hash literal to one with given key (key) and value (types) type;%sym_hash- is a shortcut for%typed_hash_castfor symbol keys;%str_hash- is a shortcut for%typed_hash_castfor string keys;%typed_array_cast- converts given array variable or array literal to one with given types (klass);%typed_array- converts given array literal to array with given type (klass); without cycles;%stringify_hash- calls#to_son keys and converts all values to given type (klass);
Ifrit.str_hash({:asd => "qwe"}, String)
class Test
extend Ifrit
def some_method
str_hash({:asd => "qwe"}, String)
end
end
str_hash_cast(hash, types)
Sourcesym_hash_cast(hash, types)
accepts any hash or named tuple example: Ifrit.as_sym_hash(hash, String | Int32)
typed_hash(hash, key, types)
accepts only hash literals example: Ifrit.typed_hash({"a" => 1, "b" => "b"}, String, Int32 | String)