fork download
  1. new_string = <<EOS
  2.   def hello
  3.   puts "Hello!"
  4.   end
  5. EOS
  6.  
  7. file_to_override = <<EOS
  8. class ApplicationController < ActionController::Base
  9.   # Prevent CSRF attacks by raising an exception.
  10.   # For APIs, you may want to use :null_session instead.
  11.   protect_from_forgery with: :exception
  12.  
  13.   helper_method :authenticated?, :current_user
  14.  
  15.   def current_user?
  16.   session[:current_user]
  17.   end
  18.  
  19. end
  20. EOS
  21.  
  22. file_to_override=file_to_override.gsub(/(.*)(\nend\b.*)/m, "\\1\n#{new_string}\\2")
  23. puts file_to_override
Success #stdin #stdout 0.05s 9664KB
stdin
Standard input is empty
stdout
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  helper_method :authenticated?, :current_user

  def current_user?
    session[:current_user]   
  end

  def hello
    puts "Hello!"
  end

end