ruby-uebungen/Assignment_036/solution/readme.md

26 lines
649 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
<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
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
```