lab42_core
Simple Ruby Core Module Extensions (for more see lab42_more)
Array
Can be used after require 'lab42/core'
or require 'lab42/core/array'
flatten_once
[].flatten_once.assert.empty?
[[2, {a: 3}, [4]], {a: 5}].flatten_once.assert ==
[2, {a: 3}, [4], {a: 5}]
For details see the corresponding QED demo.
Dir
Can be used after require 'lab42/core'
or require 'lab42/core/dir'
Dir.files "**/*" do | partial_path, full_path |
end
For details see the corresponding QED demo.
Enumerable
grep2
enum.grep2 expr # ===>
enum.partition{ |ele| expr === ele }
to_proc
And also Enumerable#to\_proc
as e.g.
counter = (1..3).to_proc
counter.().assert == 1
counter.().assert == 2
counter.().assert == 3
StopIteration.assert.raised? do
counter.()
end
For details see the corresponding QED demo.
File
expand_local_path
to get rid of the __FILE__
inside expand_path
.
For details see the corresponding QED demo.
Hash
{a: 42, b: 43}.only :a, :c # ===> {a: 42}
For details see the corresponding QED demo.
Fn
Has been moved into gem lab42_more
OpenObject
Immutable Open Objects
x = OpenObject.new a: 42
x.a.assert == 42
x[:a].assert == 42
Immutability
All modifications just return a new instance.
x = OpenObject.new a: 42, b: 43
y = x.update a: 44
y.to_hash.assert == {a: 44, b: 43}
x.a.assert == 42
For details see the corresponding QED demo.