Skip to content

Shown how to undef methods or functions with Ruby #34

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions rules/0280-Ruby.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,19 @@ Codewars [uses Ruby 2.0](http://www.codewars.com/docs/ruby-environment).
The testing framework is [inspired](http://www.codewars.com/docs/ruby-test-reference)
by [RSpec](http://rspec.info/documentation/), but not 100% compatible.

### Disabling built-in functions and methods

Ruby probably offers the best and most direct way to do that, thanks to the `undef` command.

To work with it, just put it inside the `Class` that you want to be affected, like this example to disable additions and multiplication for Integers:

```ruby
class Fixnum
undef :+,:*
end
```

Notice that in this way nothing prevents a sly user from just converting your numbers to `Float`, using the undefined operators and then converting to integers again, so be very scrupulous when you plan to undef some function, as you might need to do so in more than one form, more than one class and/or prevent conversions back and forth other classes.

<!--- this is only a placeholder -->