Class: ArrayChinese
- Inherits:
-
Array
- Object
- Array
- ArrayChinese
- Defined in:
- lib/a-b-chi.rb
Instance Method Summary collapse
-
#initialize ⇒ ArrayChinese
constructor
A new instance of ArrayChinese.
- #sort ⇒ Object
Constructor Details
#initialize ⇒ ArrayChinese
Returns a new instance of ArrayChinese.
5 6 7 8 9 10 11 |
# File 'lib/a-b-chi.rb', line 5 def initialize spec = Gem::Specification.find_by_name("a-b-chi") gem_root = spec.gem_dir gem_lib = gem_root + "/lib" @characters = File.read("#{gem_lib}/characters.txt").split("\n") end |
Instance Method Details
#sort ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/a-b-chi.rb', line 13 def sort max_length = self.max_by(&:length).length search_query = '[' for i in 0..max_length unless i == max_length search_query << "@characters.index(sort_string[#{i}]), " else search_query << "@characters.index(sort_string[#{i}])]" end end self.sort_by! { |sort_string| eval(search_query) } end |