Skip to content

Commit

Permalink
Clarify Rails::Generators::Actions#lib doc [ci-skip]
Browse files Browse the repository at this point in the history
This makes it clear that, when using the block form, the file contents
is the return value of the block, rather than the code of the block.
  • Loading branch information
jonathanhefner committed May 18, 2023
1 parent a05a5c8 commit e58a9b0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions railties/lib/rails/generators/actions.rb
Expand Up @@ -261,14 +261,17 @@ def vendor(filename, data = nil)
create_file("vendor/#{filename}", optimize_indentation(data), verbose: false)
end

# Create a new file in the <tt>lib/</tt> directory. Code can be specified
# in a block or a data string can be given.
# Creates a file in +lib/+. The contents can be specified as an argument
# or as the return value of the block.
#
# lib("crypto.rb") do
# "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'"
# lib "foreign.rb", <<~RUBY
# # Foreign code is fun
# RUBY
#
# lib "foreign.rb" do
# "# Foreign code is fun"
# end
#
# lib("foreign.rb", "# Foreign code is fun")
def lib(filename, data = nil)
log :lib, filename
data ||= yield if block_given?
Expand Down

0 comments on commit e58a9b0

Please sign in to comment.