mug 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/mug/iterator.rb CHANGED
@@ -1,2 +1,2 @@
1
- require_relative 'iterator/for'
2
- require_relative 'iterator/method'
1
+ require_relative 'iterator/for'
2
+ require_relative 'iterator/method'
@@ -1,29 +1,29 @@
1
-
2
- require_relative '../iterator_c'
3
-
4
- class Object
5
- #
6
- # Creates a new Iterator for the method named +meth+
7
- #
8
- def iter_for meth, *args
9
- Iterator.new self, meth, *args
10
- end
11
- alias :to_iter :iter_for
12
- end
13
-
14
- =begin
15
- Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
16
-
17
- Permission to use, copy, modify, and/or distribute this software for any
18
- purpose with or without fee is hereby granted, provided that the above
19
- copyright notice and this permission notice appear in all copies.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
- =end
29
-
1
+
2
+ require_relative '../iterator_c'
3
+
4
+ class Object
5
+ #
6
+ # Creates a new Iterator for the method named +meth+
7
+ #
8
+ def iter_for meth, *args
9
+ Iterator.new self, meth, *args
10
+ end
11
+ alias :to_iter :iter_for
12
+ end
13
+
14
+ =begin
15
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any
18
+ purpose with or without fee is hereby granted, provided that the above
19
+ copyright notice and this permission notice appear in all copies.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
+ =end
29
+
@@ -1,29 +1,29 @@
1
-
2
- require_relative '../iterator_c'
3
-
4
- class Method
5
- #
6
- # Creates a new Iterator for this method, initially invoked
7
- # on this method's receiver.
8
- #
9
- def to_iter *args
10
- Iterator.new receiver, name, *args
11
- end
12
- end
13
-
14
- =begin
15
- Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
16
-
17
- Permission to use, copy, modify, and/or distribute this software for any
18
- purpose with or without fee is hereby granted, provided that the above
19
- copyright notice and this permission notice appear in all copies.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
- =end
29
-
1
+
2
+ require_relative '../iterator_c'
3
+
4
+ class Method
5
+ #
6
+ # Creates a new Iterator for this method, initially invoked
7
+ # on this method's receiver.
8
+ #
9
+ def to_iter *args
10
+ Iterator.new receiver, name, *args
11
+ end
12
+ end
13
+
14
+ =begin
15
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any
18
+ purpose with or without fee is hereby granted, provided that the above
19
+ copyright notice and this permission notice appear in all copies.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
+ =end
29
+
@@ -1,44 +1,44 @@
1
-
2
- #
3
- # A special class of Enumerator that repeatedly invokes a method.
4
- #
5
- # Initially the method is send to the given +obj+, but subsequent
6
- # invocations are sent to the result of the previous invocation.
7
- #
8
- # Example:
9
- #
10
- # 0.iter_for(:next).take(5) #=> [0,1,2,3,4]
11
- #
12
- class Iterator < Enumerator
13
- #
14
- # Creates a new Iterator for method +meth+, to be
15
- # called initially on object +obj+.
16
- #
17
- # All method calls will have +args+ as parameters.
18
- #
19
- def initialize obj, meth, *args
20
- super() do |y|
21
- loop do
22
- y << obj
23
- obj = obj.send(meth, *args)
24
- end
25
- end
26
- end
27
- end
28
-
29
- =begin
30
- Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
31
-
32
- Permission to use, copy, modify, and/or distribute this software for any
33
- purpose with or without fee is hereby granted, provided that the above
34
- copyright notice and this permission notice appear in all copies.
35
-
36
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
- =end
44
-
1
+
2
+ #
3
+ # A special class of Enumerator that repeatedly invokes a method.
4
+ #
5
+ # Initially the method is send to the given +obj+, but subsequent
6
+ # invocations are sent to the result of the previous invocation.
7
+ #
8
+ # Example:
9
+ #
10
+ # 0.iter_for(:next).take(5) #=> [0,1,2,3,4]
11
+ #
12
+ class Iterator < Enumerator
13
+ #
14
+ # Creates a new Iterator for method +meth+, to be
15
+ # called initially on object +obj+.
16
+ #
17
+ # All method calls will have +args+ as parameters.
18
+ #
19
+ def initialize obj, meth, *args
20
+ super() do |y|
21
+ loop do
22
+ y << obj
23
+ obj = obj.send(meth, *args)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ =begin
30
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
31
+
32
+ Permission to use, copy, modify, and/or distribute this software for any
33
+ purpose with or without fee is hereby granted, provided that the above
34
+ copyright notice and this permission notice appear in all copies.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
+ =end
44
+
data/lib/mug/maybe.rb CHANGED
@@ -1,59 +1,59 @@
1
-
2
- #
3
- # Invokes methods on a wrapped object, if that object is truthy.
4
- #
5
- class MaybeDelegator
6
- #
7
- # Creates a new MaybeDelegator, wrapping +o+
8
- #
9
- def initialize o
10
- @o = o
11
- end
12
-
13
- #
14
- # Returns this MaybeDelegator object.
15
- #
16
- def maybe
17
- self
18
- end
19
-
20
- # Calls the method on +@o+ if it's truthy.
21
- def method_missing *a, &b #:nodoc:
22
- @o && @o.send(*a, &b)
23
- end
24
- end
25
-
26
- class Object
27
- #
28
- # Do something if this object is truthy.
29
- #
30
- # If a block is given, it is executed in the context of this
31
- # object, iff this object is neither +nil+ nor +false+.
32
- #
33
- # If no block is given, returns a MaybeDelegator object.
34
- #
35
- def maybe &b
36
- if b
37
- self && instance_eval(&b)
38
- else
39
- MaybeDelegator.new(self)
40
- end
41
- end
42
- end
43
-
44
- =begin
45
- Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
46
-
47
- Permission to use, copy, modify, and/or distribute this software for any
48
- purpose with or without fee is hereby granted, provided that the above
49
- copyright notice and this permission notice appear in all copies.
50
-
51
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
52
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
53
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
54
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
55
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
56
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
57
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
58
- =end
59
-
1
+
2
+ #
3
+ # Invokes methods on a wrapped object, if that object is truthy.
4
+ #
5
+ class MaybeDelegator
6
+ #
7
+ # Creates a new MaybeDelegator, wrapping +o+
8
+ #
9
+ def initialize o
10
+ @o = o
11
+ end
12
+
13
+ #
14
+ # Returns this MaybeDelegator object.
15
+ #
16
+ def maybe
17
+ self
18
+ end
19
+
20
+ # Calls the method on +@o+ if it's truthy.
21
+ def method_missing *a, &b #:nodoc:
22
+ @o && @o.send(*a, &b)
23
+ end
24
+ end
25
+
26
+ class Object
27
+ #
28
+ # Do something if this object is truthy.
29
+ #
30
+ # If a block is given, it is executed in the context of this
31
+ # object, iff this object is neither +nil+ nor +false+.
32
+ #
33
+ # If no block is given, returns a MaybeDelegator object.
34
+ #
35
+ def maybe &b
36
+ if b
37
+ self && instance_eval(&b)
38
+ else
39
+ MaybeDelegator.new(self)
40
+ end
41
+ end
42
+ end
43
+
44
+ =begin
45
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
46
+
47
+ Permission to use, copy, modify, and/or distribute this software for any
48
+ purpose with or without fee is hereby granted, provided that the above
49
+ copyright notice and this permission notice appear in all copies.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
52
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
53
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
54
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
55
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
56
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
57
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
58
+ =end
59
+
data/lib/mug/self.rb CHANGED
@@ -1,33 +1,33 @@
1
-
2
- class Object
3
- #
4
- # Returns this object.
5
- #
6
- # If a block is given, this object is yielded to it, and the result
7
- # is returned.
8
- #
9
- def self(&block)
10
- if block_given?
11
- yield self
12
- else
13
- self
14
- end
15
- end
16
- end
17
-
18
- =begin
19
- Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
20
-
21
- Permission to use, copy, modify, and/or distribute this software for any
22
- purpose with or without fee is hereby granted, provided that the above
23
- copyright notice and this permission notice appear in all copies.
24
-
25
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
26
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
27
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
28
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32
- =end
33
-
1
+
2
+ class Object
3
+ #
4
+ # Returns this object.
5
+ #
6
+ # If a block is given, this object is yielded to it, and the result
7
+ # is returned.
8
+ #
9
+ def self(&block)
10
+ if block_given?
11
+ yield self
12
+ else
13
+ self
14
+ end
15
+ end
16
+ end
17
+
18
+ =begin
19
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
20
+
21
+ Permission to use, copy, modify, and/or distribute this software for any
22
+ purpose with or without fee is hereby granted, provided that the above
23
+ copyright notice and this permission notice appear in all copies.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
26
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
27
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
28
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32
+ =end
33
+
data/lib/mug/tau.rb CHANGED
@@ -1,44 +1,44 @@
1
-
2
- module Math
3
- # The true circle constant.
4
- # The ratio of a circle's circumference to its radius.
5
- TAU = PI * 2.0
6
- end
7
-
8
- module BigMath
9
- ##
10
- # Computes the value of tau to the specific number of digits of precision.
11
- #
12
- # @param [Integer] prec the number of decimal digits of precision in the computed value.
13
- # @return [BigDecimal] the computed value
14
- # @raise [ArgumentError] if +prec+ is not positive
15
- #
16
- # @example
17
- # require 'bigdecimal'
18
- # require 'bigdecimal/math'
19
- # include BigMath
20
- #
21
- # puts TAU(150)
22
- #
23
- def TAU(prec)
24
- raise ArgumentError, 'Zero or negative argument for TAU' if prec <= 0
25
- PI(prec) * BigDecimal('2')
26
- end
27
- end
28
-
29
- =begin
30
- Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
31
-
32
- Permission to use, copy, modify, and/or distribute this software for any
33
- purpose with or without fee is hereby granted, provided that the above
34
- copyright notice and this permission notice appear in all copies.
35
-
36
- THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
- =end
44
-
1
+
2
+ module Math
3
+ # The true circle constant.
4
+ # The ratio of a circle's circumference to its radius.
5
+ TAU = PI * 2.0
6
+ end
7
+
8
+ module BigMath
9
+ ##
10
+ # Computes the value of tau to the specific number of digits of precision.
11
+ #
12
+ # @param [Integer] prec the number of decimal digits of precision in the computed value.
13
+ # @return [BigDecimal] the computed value
14
+ # @raise [ArgumentError] if +prec+ is not positive
15
+ #
16
+ # @example
17
+ # require 'bigdecimal'
18
+ # require 'bigdecimal/math'
19
+ # include BigMath
20
+ #
21
+ # puts TAU(150)
22
+ #
23
+ def TAU(prec)
24
+ raise ArgumentError, 'Zero or negative argument for TAU' if prec <= 0
25
+ PI(prec) * BigDecimal('2')
26
+ end
27
+ end
28
+
29
+ =begin
30
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
31
+
32
+ Permission to use, copy, modify, and/or distribute this software for any
33
+ purpose with or without fee is hereby granted, provided that the above
34
+ copyright notice and this permission notice appear in all copies.
35
+
36
+ THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
+ =end
44
+