ruby-uebungen/Assignment_040/solution/readme.md

26 lines
649 B
Markdown
Raw Normal View History

2023-05-23 09:19:31 +02:00
# Lösung: Eigenclass einer Klasse
<div style="border: 1px solid grey;"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>```ruby
class Numeric
class << self
def to_binary(n)
n.to_s(2)
end
end
end
puts Numeric::to_binary(47)
```
Alternative Lösung:
```ruby
class << Numeric
def to_binary(n)
n.to_s(2)
end
end
puts Numeric::to_binary(47)
```