Skip to content

wcコマンドの作成#8

Open
thmz337 wants to merge 2 commits intomainfrom
thmz337-wc
Open

wcコマンドの作成#8
thmz337 wants to merge 2 commits intomainfrom
thmz337-wc

Conversation

@thmz337
Copy link
Copy Markdown
Owner

@thmz337 thmz337 commented Jun 23, 2024

No description provided.

05.wc/wc.rb Outdated
ENV['POSIXLY_CORRECT'] = '1'

def count_lines
proc { |input| input.readlines.size }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

メソッドの中でprocを使っているのは普通のメソッドとして他のシチュエーションで使いずらいのでちょっとトリッキーかもしれません。

メソッドを持ち運びたければmethodメソッドを使うとMethodオブジェクトに変換できます。
また、文字列を持ち運んで、実行するときに文字列をMethodオブジェクトに変換するのもいいかもしれません。

def hello(name)
  puts "hello #{name}"
end

hello('world') # => hello world

puts method('hello') # => #<Method: Object#hello(name) method_call.rb:1>

method('hello').call('world') # => hello world

Copy link
Copy Markdown

@komagata komagata left a comment

Choose a reason for hiding this comment

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

確認させていただきました。OKです〜🙆‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants