Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ $ rand_chinese_name
```


```
require 'benchmark'

Benchmark.measure { 100_000.times { ChineseName.generate } }

=> #<Benchmark::Tms:0x007fa60b1bb238 @label="", @real=44.099358999868855, @cstime=0.0, @cutime=0.0, @stime=2.7199999999999998, @utime=36.43, @total=39.15>


require 'ffaker'
FFaker::NameCN


```


## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
4 changes: 2 additions & 2 deletions lib/chinese_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def generate_first_name
end

def generate_word
word = (19_968..20_901).to_a.sample
word = Random.rand(19_968..40_869)
[word.to_s(16)].pack('H*').force_encoding('utf-16be').encode('utf-8')
end

Expand All @@ -50,7 +50,7 @@ def generate_last_name
end

def all_last_name
IO.foreach(file_data).inject([]) { |arr, line| arr << line.strip }
@@all_last_name ||= IO.foreach(file_data).inject([]) { |arr, line| arr << line.strip }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace class var @@all_last_name with a class instance var.
Line is too long. [90/80]

end

def file_data
Expand Down