Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying frozen string #1

Open
Macavirus opened this issue Feb 6, 2019 · 0 comments
Open

Modifying frozen string #1

Macavirus opened this issue Feb 6, 2019 · 0 comments

Comments

@Macavirus
Copy link

Macavirus commented Feb 6, 2019

constant RESERVED_NAMES is a frozen array, and thus can't be mutated with the << method.

def add_default_handlers
# Puts (for debugging)
@handlers["#{NAMESPACE}.puts"] = Proc.new { |dialog, *arguments|
puts(*arguments.map { |argument| argument.inspect })
}
RESERVED_NAMES << "#{NAMESPACE}.puts"
# Error channel (for debugging)
@handlers["#{NAMESPACE}.error"] = Proc.new { |dialog, type, message, backtrace|
log_error(type + ': ' + message, {:language => 'javascript', :backtrace => backtrace})
}
RESERVED_NAMES << "#{NAMESPACE}.error"
end

Could either remove the call to freeze or refactor this to be a pure function that takes the old RESERVED_NAMES as an argument and returns a new array. What do you think?

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

No branches or pull requests

1 participant