ruby-uebungen/Assignment_036/solution/readme.md

27 lines
287 B
Markdown
Raw Normal View History

2023-05-25 17:47:19 +02:00
# Lösung: Eigenclass einer Klasse
2023-05-23 09:19:31 +02:00
2023-05-25 17:49:42 +02:00
```ruby
2023-05-25 17:47:19 +02:00
class Numeric
class << self
def to_binary(n)
n.to_s(2)
end
end
2023-05-23 09:19:31 +02:00
end
2023-05-25 17:47:19 +02:00
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)
2023-05-23 09:19:31 +02:00
```