diff options
| -rw-r--r-- | doc/compile/README.md | 28 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 20 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/test/hash.rb | 9 |
3 files changed, 57 insertions, 0 deletions
diff --git a/doc/compile/README.md b/doc/compile/README.md index 70fe88311..8928a0086 100644 --- a/doc/compile/README.md +++ b/doc/compile/README.md @@ -110,6 +110,34 @@ Configuration of the C compiler binary, flags and include paths. cc.compile_options = ... end +C Compiler has header searcher to detect installed library. + +If you need a include path of header file use ```search_header_path```: + + # Searches ```iconv.h```. + # If found it will return include path of the header file. + # Otherwise it will return nil . + fail 'iconv.h not found' unless conf.cc.search_header_path 'iconv.h' + +If you need a full file name of header file use ```search_header```: + + # Searches ```iconv.h```. + # If found it will return full path of the header file. + # Otherwise it will return nil . + iconv_h = conf.cc.search_header 'iconv.h' + print "iconv.h found: #{iconv_h}\n" + +Header searcher uses compiler's ```include_paths``` by default. +When you are using GCC toolchain (including clang toolchain since its base is gcc toolchain) +it will use compiler specific include paths too. (For example ```/usr/local/include```, ```/usr/include```) + +If you need a special header search paths define a singleton method ```header_search_paths``` to C compiler: + + def conf.cc.header_search_paths + ['/opt/local/include'] + include_paths + end + + ### Linker Configuration of the Linker binary, flags and library paths. diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index ce8fa3577..1ebc540e8 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -100,4 +100,24 @@ class Hash end self end + + ## + # call-seq: + # hash.flatten -> an_array + # hash.flatten(level) -> an_array + # + # Returns a new array that is a one-dimensional flattening of this + # hash. That is, for every key or value that is an array, extract + # its elements into the new array. Unlike Array#flatten, this + # method does not flatten recursively by default. The optional + # <i>level</i> argument determines the level of recursion to flatten. + # + # a = {1=> "one", 2 => [2,"two"], 3 => "three"} + # a.flatten # => [1, "one", 2, [2, "two"], 3, "three"] + # a.flatten(2) # => [1, "one", 2, 2, "two", 3, "three"] + # + + def flatten(level=1) + self.to_a.flatten(level) + end end diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index 4c7dbb217..7d8d66b4e 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -73,3 +73,12 @@ assert("Hash#delete_if") do } assert_equal(base.size, n) end + +assert("Hash#flatten") do + a = {1=> "one", 2 => [2,"two"], 3 => [3, ["three"]]} + assert_equal [1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten + assert_equal [[1, "one"], [2, [2, "two"]], [3, [3, ["three"]]]], a.flatten(0) + assert_equal [1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(1) + assert_equal [1, "one", 2, 2, "two", 3, 3, ["three"]], a.flatten(2) + assert_equal [1, "one", 2, 2, "two", 3, 3, "three"], a.flatten(3) +end |
