summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/mruby-array-ext/mrblib/array.rb41
-rw-r--r--mrbgems/mruby-array-ext/test/array.rb8
-rw-r--r--mrbgems/mruby-compiler/core/parse.y2
-rw-r--r--mrbgems/mruby-compiler/core/y.tab.c2
-rw-r--r--mrbgems/mruby-complex/src/complex.c2
-rw-r--r--mrbgems/mruby-enum-ext/mrblib/enum.rb2
-rw-r--r--mrbgems/mruby-io/README.md4
-rw-r--r--mrbgems/mruby-kernel-ext/src/kernel.c2
-rw-r--r--mrbgems/mruby-kernel-ext/test/kernel.rb2
-rw-r--r--mrbgems/mruby-method/README.md46
-rw-r--r--mrbgems/mruby-method/test/method.rb6
-rw-r--r--mrbgems/mruby-proc-ext/test/proc.rb1
-rw-r--r--mrbgems/mruby-sleep/README.md8
-rw-r--r--mrbgems/mruby-socket/README.md16
-rw-r--r--mrbgems/mruby-sprintf/src/sprintf.c8
-rw-r--r--mrbgems/mruby-test/README.md4
16 files changed, 103 insertions, 51 deletions
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb
index 0195a6970..becfcb3ca 100644
--- a/mrbgems/mruby-array-ext/mrblib/array.rb
+++ b/mrbgems/mruby-array-ext/mrblib/array.rb
@@ -193,6 +193,47 @@ class Array
##
# call-seq:
+ # ary.intersect?(other_ary) -> true or false
+ #
+ # Returns +true+ if the array and +other_ary+ have at least one element in
+ # common, otherwise returns +false+.
+ #
+ # a = [ 1, 2, 3 ]
+ # b = [ 3, 4, 5 ]
+ # c = [ 5, 6, 7 ]
+ # a.intersect?(b) #=> true
+ # a.intersect?(c) #=> false
+ def intersect?(ary)
+ raise TypeError, "can't convert #{ary.class} into Array" unless ary.class == Array
+
+ hash = {}
+ if self.length > ary.length
+ shorter = ary
+ longer = self
+ else
+ shorter = self
+ longer = ary
+ end
+ idx = 0
+ len = shorter.size
+ while idx < len
+ hash[shorter[idx]] = true
+ idx += 1
+ end
+ idx = 0
+ len = size
+ while idx < len
+ v = longer[idx]
+ if hash[v]
+ return true
+ end
+ idx += 1
+ end
+ false
+ end
+
+ ##
+ # call-seq:
# ary.flatten -> new_ary
# ary.flatten(level) -> new_ary
#
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb
index 2955ef391..3f73ad8b9 100644
--- a/mrbgems/mruby-array-ext/test/array.rb
+++ b/mrbgems/mruby-array-ext/test/array.rb
@@ -119,6 +119,14 @@ assert("Array#intersection") do
assert_equal [1, 8], a.intersection(b,c)
end
+assert("Array#intersect?") do
+ a = [ 1, 2, 3 ]
+ b = [ 3, 4, 5 ]
+ c = [ 5, 6, 7 ]
+ assert_true(a.intersect?(b))
+ assert_false(a.intersect?(c))
+end
+
assert("Array#flatten") do
assert_equal [1, 2, "3", {4=>5}, :'6'], [1, 2, "3", {4=>5}, :'6'].flatten
assert_equal [1, 2, 3, 4, 5, 6], [1, 2, [3, 4, 5], 6].flatten
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 0bd8e7daf..2c2bff714 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -5865,7 +5865,7 @@ parser_yylex(parser_state *p)
tokfix(p);
if (is_float) {
#ifdef MRB_NO_FLOAT
- yywarning_s(p, "floating point numbers are not supported", tok(p));
+ yywarning_s(p, "floating-point numbers are not supported", tok(p));
pylval.nd = new_int(p, "0", 10, 0);
return tINTEGER;
#else
diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c
index b27b6a136..137e4d4cf 100644
--- a/mrbgems/mruby-compiler/core/y.tab.c
+++ b/mrbgems/mruby-compiler/core/y.tab.c
@@ -11895,7 +11895,7 @@ parser_yylex(parser_state *p)
tokfix(p);
if (is_float) {
#ifdef MRB_NO_FLOAT
- yywarning_s(p, "floating point numbers are not supported", tok(p));
+ yywarning_s(p, "floating-point numbers are not supported", tok(p));
pylval.nd = new_int(p, "0", 10, 0);
return tINTEGER;
#else
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index 0bf5377ed..968d3fe2e 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -300,7 +300,7 @@ complex_div(mrb_state *mrb, mrb_value self)
b = complex_ptr(mrb, rhs);
- /* Split floating point components into significand and exponent */
+ /* Split floating-point components into significand and exponent */
ar.s = F(frexp)(a->real, &ar.x);
ai.s = F(frexp)(a->imaginary, &ai.x);
br.s = F(frexp)(b->real, &br.x);
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb
index f15511925..5f39235e0 100644
--- a/mrbgems/mruby-enum-ext/mrblib/enum.rb
+++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb
@@ -428,7 +428,7 @@ module Enumerable
max = min = val.__svalue
max_cmp = min_cmp = block.call(*val)
first = false
- else
+ else
if (cmp = block.call(*val)) > max_cmp
max = val.__svalue
max_cmp = cmp
diff --git a/mrbgems/mruby-io/README.md b/mrbgems/mruby-io/README.md
index 2c5d7a9ac..a518e6169 100644
--- a/mrbgems/mruby-io/README.md
+++ b/mrbgems/mruby-io/README.md
@@ -15,7 +15,7 @@ Add the line below to your build configuration.
### IO
- - https://doc.ruby-lang.org/ja/1.9.3/class/IO.html
+* <https://doc.ruby-lang.org/ja/1.9.3/class/IO.html>
| method | mruby-io | memo |
| ------------------------- | -------- | ---- |
@@ -100,7 +100,7 @@ Add the line below to your build configuration.
### File
- - https://doc.ruby-lang.org/ja/1.9.3/class/File.html
+* <https://doc.ruby-lang.org/ja/1.9.3/class/File.html>
| method | mruby-io | memo |
| --------------------------- | -------- | ---- |
diff --git a/mrbgems/mruby-kernel-ext/src/kernel.c b/mrbgems/mruby-kernel-ext/src/kernel.c
index 2a0ca3a9d..7afa6fa5f 100644
--- a/mrbgems/mruby-kernel-ext/src/kernel.c
+++ b/mrbgems/mruby-kernel-ext/src/kernel.c
@@ -86,7 +86,7 @@ mrb_f_method(mrb_state *mrb, mrb_value self)
* Integer(arg,base=0) -> integer
*
* Converts <i>arg</i> to a <code>Integer</code>.
- * Numeric types are converted directly (with floating point numbers
+ * Numeric types are converted directly (with floating-point numbers
* being truncated). <i>base</i> (0, or between 2 and 36) is a base for
* integer string representation. If <i>arg</i> is a <code>String</code>,
* when <i>base</i> is omitted or equals to zero, radix indicators
diff --git a/mrbgems/mruby-kernel-ext/test/kernel.rb b/mrbgems/mruby-kernel-ext/test/kernel.rb
index 2ac194dca..fc4402b3d 100644
--- a/mrbgems/mruby-kernel-ext/test/kernel.rb
+++ b/mrbgems/mruby-kernel-ext/test/kernel.rb
@@ -21,7 +21,7 @@ assert('Kernel.caller, Kernel#caller') do
end
end
- skip "backtrace isn't available" if(c.new.baz(0)[0].include?("unknown"))
+ skip "backtrace isn't available" if (c.new.baz(0)[0].include?("unknown"))
assert_equal "kernel.rb:#{caller_lineno}:in foo", c.new.baz(0)[0][-19..-1]
assert_equal "bar", c.new.baz[0][-3..-1]
diff --git a/mrbgems/mruby-method/README.md b/mrbgems/mruby-method/README.md
index eef414c55..f299718df 100644
--- a/mrbgems/mruby-method/README.md
+++ b/mrbgems/mruby-method/README.md
@@ -23,38 +23,38 @@ end
## Kernel
-- `Kernel#method`
-- `Kernel#singleton_method`
+* `Kernel#method`
+* `Kernel#singleton_method`
## Module
-- `Module#instance_method`
+* `Module#instance_method`
## Method class
-- `Method#name`
-- `Method#call`
-- `Method#super_method`
-- `Method#arity`
-- `Method#unbind`
-- `Method#[]`
-- `Method#owner`
-- `Method#receiver`
-- `Method#parameters`
-- `Method#source_location`
-- `Method#to_proc`
+* `Method#name`
+* `Method#call`
+* `Method#super_method`
+* `Method#arity`
+* `Method#unbind`
+* `Method#[]`
+* `Method#owner`
+* `Method#receiver`
+* `Method#parameters`
+* `Method#source_location`
+* `Method#to_proc`
## UnboundMethod class
-- `UnboundMethod#name`
-- `UnboundMethod#bind`
-- `UnboundMethod#super_method`
-- `UnboundMethod#arity`
-- `UnboundMethod#owner`
-- `UnboundMethod#parameters`
-- `UnboundMethod#source_location`
+* `UnboundMethod#name`
+* `UnboundMethod#bind`
+* `UnboundMethod#super_method`
+* `UnboundMethod#arity`
+* `UnboundMethod#owner`
+* `UnboundMethod#parameters`
+* `UnboundMethod#source_location`
# See also
-- https://ruby-doc.org/core-2.3.3/Method.html
-- https://ruby-doc.org/core-2.3.3/UnboundMethod.html
+* <https://ruby-doc.org/core-2.3.3/Method.html>
+* <https://ruby-doc.org/core-2.3.3/UnboundMethod.html>
diff --git a/mrbgems/mruby-method/test/method.rb b/mrbgems/mruby-method/test/method.rb
index 123ae34be..a7db20031 100644
--- a/mrbgems/mruby-method/test/method.rb
+++ b/mrbgems/mruby-method/test/method.rb
@@ -92,9 +92,9 @@ assert 'Method#call' do
assert_equal 42, klass2.new.method(:foo).call
i = Class.new {
- def bar
- yield 3
- end
+ def bar
+ yield 3
+ end
}.new
assert_raise(LocalJumpError) { i.method(:bar).call }
assert_equal 3, i.method(:bar).call { |i| i }
diff --git a/mrbgems/mruby-proc-ext/test/proc.rb b/mrbgems/mruby-proc-ext/test/proc.rb
index 113afcc5e..06365b7d9 100644
--- a/mrbgems/mruby-proc-ext/test/proc.rb
+++ b/mrbgems/mruby-proc-ext/test/proc.rb
@@ -10,6 +10,7 @@ def enable_debug_info?
if(@enable_debug_info && e.backtrace[0].include?("(unknown)"))
@enable_debug_info = false
end
+ return @enable_debug_info
end
end
diff --git a/mrbgems/mruby-sleep/README.md b/mrbgems/mruby-sleep/README.md
index cddae7c13..ed9c2730a 100644
--- a/mrbgems/mruby-sleep/README.md
+++ b/mrbgems/mruby-sleep/README.md
@@ -2,9 +2,9 @@
mruby sleep module
-## install by mrbgems
+## Install by mrbgems
-- add `conf.gem` line to your build configuration.
+* add `conf.gem` line to your build configuration.
```ruby
MRuby::Build.new do |conf|
@@ -15,7 +15,7 @@ MRuby::Build.new do |conf|
end
```
-## example
+## Example
```ruby
sleep(10)
@@ -26,4 +26,4 @@ usleep(10000)
under the MIT License:
-* https://www.opensource.org/licenses/mit-license.php
+* <https://www.opensource.org/licenses/mit-license.php>
diff --git a/mrbgems/mruby-socket/README.md b/mrbgems/mruby-socket/README.md
index fd20548aa..b727dc982 100644
--- a/mrbgems/mruby-socket/README.md
+++ b/mrbgems/mruby-socket/README.md
@@ -21,17 +21,17 @@ Date: Tue, 21 May 2013 04:31:30 GMT
## Requirement
-- [mruby-io](https://github.com/mruby/mruby/tree/master/mrbgems/mruby-io) mrbgem
-- [iij/mruby-mtest](https://github.com/iij/mruby-mtest) mrgbem to run tests
-- system must have RFC3493 basic socket interface
-- and some POSIX API...
+* [mruby-io](https://github.com/mruby/mruby/tree/master/mrbgems/mruby-io) mrbgem
+* [iij/mruby-mtest](https://github.com/iij/mruby-mtest) mrgbem to run tests
+* system must have RFC3493 basic socket interface
+* and some POSIX API...
## TODO
-- add missing methods
-- write more tests
-- fix possible descriptor leakage (see XXX comments)
-- `UNIXSocket#recv_io` `UNIXSocket#send_io`
+* add missing methods
+* write more tests
+* fix possible descriptor leakage (see XXX comments)
+* `UNIXSocket#recv_io` `UNIXSocket#send_io`
## License
diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c
index f6dab159d..839ee4dc4 100644
--- a/mrbgems/mruby-sprintf/src/sprintf.c
+++ b/mrbgems/mruby-sprintf/src/sprintf.c
@@ -312,21 +312,21 @@ get_hash(mrb_state *mrb, mrb_value *hash, mrb_int argc, const mrb_value *argv)
*
* Field | Float Format
* ------+--------------------------------------------------------------
- * e | Convert floating point argument into exponential notation
+ * e | Convert floating-point argument into exponential notation
* | with one digit before the decimal point as [-]d.dddddde[+-]dd.
* | The precision specifies the number of digits after the decimal
* | point (defaulting to six).
* E | Equivalent to 'e', but uses an uppercase E to indicate
* | the exponent.
- * f | Convert floating point argument as [-]ddd.dddddd,
+ * f | Convert floating-point argument as [-]ddd.dddddd,
* | where the precision specifies the number of digits after
* | the decimal point.
- * g | Convert a floating point number using exponential form
+ * g | Convert a floating-point number using exponential form
* | if the exponent is less than -4 or greater than or
* | equal to the precision, or in dd.dddd form otherwise.
* | The precision specifies the number of significant digits.
* G | Equivalent to 'g', but use an uppercase 'E' in exponent form.
- * a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
+ * a | Convert floating-point argument as [-]0xh.hhhhp[+-]dd,
* | which is consisted from optional sign, "0x", fraction part
* | as hexadecimal, "p", and exponential part as decimal.
* A | Equivalent to 'a', but use uppercase 'X' and 'P'.
diff --git a/mrbgems/mruby-test/README.md b/mrbgems/mruby-test/README.md
index c0bceecd7..86b1ce05e 100644
--- a/mrbgems/mruby-test/README.md
+++ b/mrbgems/mruby-test/README.md
@@ -3,4 +3,6 @@ Running Tests
To run the tests, execute the following from the project's root directory.
- $ make test
+```
+$ make test
+```