diff --git a/Assignment_001/solution/readme.md b/Assignment_001/solution/readme.md index 446d69a..9312361 100644 --- a/Assignment_001/solution/readme.md +++ b/Assignment_001/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Bedingte Zuweisung -


















































```ruby + +```ruby a = nil a ||= 'leer' ``` diff --git a/Assignment_002/solution/readme.md b/Assignment_002/solution/readme.md index b4a1c6e..b996936 100644 --- a/Assignment_002/solution/readme.md +++ b/Assignment_002/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Case -




























































+ + ```ruby note = 3 text = case note diff --git a/Assignment_003/solution/readme.md b/Assignment_003/solution/readme.md index c20cefe..0da67e6 100644 --- a/Assignment_003/solution/readme.md +++ b/Assignment_003/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: String-Formatierung -


















































+ + ```ruby name = "Peter" gewicht = 90 diff --git a/Assignment_004/solution/readme.md b/Assignment_004/solution/readme.md index c470e91..dda6f35 100644 --- a/Assignment_004/solution/readme.md +++ b/Assignment_004/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Parallele Zuweisung -






























+ + ```ruby def swap(a, b) [ b, a ] diff --git a/Assignment_005/solution/readme.md b/Assignment_005/solution/readme.md index 03e48c6..01b08cd 100644 --- a/Assignment_005/solution/readme.md +++ b/Assignment_005/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Ranges -




















+ + ```ruby (1..20).each { |e| puts e } ``` \ No newline at end of file diff --git a/Assignment_006/solution/readme.md b/Assignment_006/solution/readme.md index c2ce89f..aab3c41 100644 --- a/Assignment_006/solution/readme.md +++ b/Assignment_006/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Splat -








































+ + ```ruby ort = [ 49.468408, 8.482504, \ 'Hochschule Mannheim', \ diff --git a/Assignment_007/solution/readme.md b/Assignment_007/solution/readme.md index 2605fa6..d7fd431 100644 --- a/Assignment_007/solution/readme.md +++ b/Assignment_007/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Symbole -


















































+ + ```ruby def ansage(ursache) diff --git a/Assignment_008/solution/readme.md b/Assignment_008/solution/readme.md index 80c44db..fe5df6c 100644 --- a/Assignment_008/solution/readme.md +++ b/Assignment_008/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Zugriffsmethoden -






























+ + ```ruby class Professor attr_reader :name diff --git a/Assignment_009/solution/readme.md b/Assignment_009/solution/readme.md index 09041b5..96eb619 100644 --- a/Assignment_009/solution/readme.md +++ b/Assignment_009/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Klasse deklarieren -




































































































```ruby + +```ruby class Ticket attr_reader :spiel diff --git a/Assignment_010/solution/readme.md b/Assignment_010/solution/readme.md index 0b27d63..acf6509 100644 --- a/Assignment_010/solution/readme.md +++ b/Assignment_010/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Default Parameter -




























































```ruby + +```ruby def produkt(a, b, c = 1, d = 1) a * b * c * d end diff --git a/Assignment_011/solution/readme.md b/Assignment_011/solution/readme.md index 16e8d87..fa6b102 100644 --- a/Assignment_011/solution/readme.md +++ b/Assignment_011/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Vererbung -
















































































```ruby + +```ruby class Mensch attr_reader :name, :alte diff --git a/Assignment_012/solution/readme.md b/Assignment_012/solution/readme.md index 392bddd..676b08f 100644 --- a/Assignment_012/solution/readme.md +++ b/Assignment_012/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Keyword-Parameter -




























































```ruby + +```ruby def greet(vorname:, nachname:) puts "Hello #{vorname} #{nachname}" end diff --git a/Assignment_013/solution/readme.md b/Assignment_013/solution/readme.md index 4ac0b94..b4a1fcb 100644 --- a/Assignment_013/solution/readme.md +++ b/Assignment_013/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Mixin benutzen -
















































































```ruby + +```ruby class Squares include Enumerable diff --git a/Assignment_014/solution/readme.md b/Assignment_014/solution/readme.md index 17c8a6b..59ad22f 100644 --- a/Assignment_014/solution/readme.md +++ b/Assignment_014/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Modul schreiben -






























```ruby + +```ruby module Chemie N_a = 6.02214179E23 M_v = 22.413996 diff --git a/Assignment_015/solution/readme.md b/Assignment_015/solution/readme.md index 24e591a..3cf5948 100644 --- a/Assignment_015/solution/readme.md +++ b/Assignment_015/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Monkey Patch -




























































```ruby + +```ruby class String def to_leet self.tr('aeiou', '43107') diff --git a/Assignment_016/solution/readme.md b/Assignment_016/solution/readme.md index 9d01955..2c28f32 100644 --- a/Assignment_016/solution/readme.md +++ b/Assignment_016/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Geschachtelte Methoden -


















































```ruby + +```ruby class Bomb def self.activate def explode diff --git a/Assignment_017/solution/readme.md b/Assignment_017/solution/readme.md index 1a7f291..11f313f 100644 --- a/Assignment_017/solution/readme.md +++ b/Assignment_017/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Vararg-Methoden -




























































```ruby + +```ruby def produkt(*p) p.reduce { |s, e| s *= e } end diff --git a/Assignment_018/solution/readme.md b/Assignment_018/solution/readme.md index a54b6e1..30c8b18 100644 --- a/Assignment_018/solution/readme.md +++ b/Assignment_018/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Arrays -




































































































```ruby + +```ruby stapel = [] for farbe in %w{P X H K} diff --git a/Assignment_019/solution/readme.md b/Assignment_019/solution/readme.md index 060a4f5..0bf3f95 100644 --- a/Assignment_019/solution/readme.md +++ b/Assignment_019/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Callback mit Block -
















































































```ruby + +```ruby def rechner(a, b) ergebnis = yield a, b ergebnis * 2 diff --git a/Assignment_020/solution/readme.md b/Assignment_020/solution/readme.md index 450f2da..e5e47f7 100644 --- a/Assignment_020/solution/readme.md +++ b/Assignment_020/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Callback mit Proc -
















































































```ruby + +```ruby def rechner(a, b, lam = nil, &block) lam ||= block ergebnis = lam.call(a, b) diff --git a/Assignment_021/solution/readme.md b/Assignment_021/solution/readme.md index 2558771..d7e96eb 100644 --- a/Assignment_021/solution/readme.md +++ b/Assignment_021/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Closure -
















































































```ruby + +```ruby def create_counter n = 0 # closure Proc.new { n += 1 } diff --git a/Assignment_022/solution/readme.md b/Assignment_022/solution/readme.md index 7592c79..b144373 100644 --- a/Assignment_022/solution/readme.md +++ b/Assignment_022/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Hashes und Blöcke -
















































































```ruby + +```ruby class Cache def initialize(&callback) @data = {} diff --git a/Assignment_023/solution/readme.md b/Assignment_023/solution/readme.md index dff8a9c..8baf991 100644 --- a/Assignment_023/solution/readme.md +++ b/Assignment_023/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Hashes -




























































+ + ```ruby worte = %w{ Bier Schnaps Bier Vodka Rum Baileys Rum Bier Vodka Bier Hugo } diff --git a/Assignment_024/solution/readme.md b/Assignment_024/solution/readme.md index 10eb367..e62a6a3 100644 --- a/Assignment_024/solution/readme.md +++ b/Assignment_024/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Map -
















































































+ + ```ruby def leeter(array) array.map do |e| diff --git a/Assignment_025/solution/readme.md b/Assignment_025/solution/readme.md index 74f22f7..4292e85 100644 --- a/Assignment_025/solution/readme.md +++ b/Assignment_025/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Map und Reduce -
















































































+ + ```ruby def char_count(array) counts = array.map { |e| e.length } diff --git a/Assignment_026/solution/readme.md b/Assignment_026/solution/readme.md index db43e48..bddadc2 100644 --- a/Assignment_026/solution/readme.md +++ b/Assignment_026/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Ausnahmen -








































```ruby + +```ruby def division(a, b) raise ArgumentError unless (a.is_a? Numeric) && (b.is_a? Numeric) raise ZeroDivisionError if b == 0 diff --git a/Assignment_027/solution/readme.md b/Assignment_027/solution/readme.md index d2e01d8..59d381e 100644 --- a/Assignment_027/solution/readme.md +++ b/Assignment_027/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Klasse Dir und IO -
















































































```ruby + +```ruby def print(f) n = 0 puts f, "\n" diff --git a/Assignment_028/solution/readme.md b/Assignment_028/solution/readme.md index 8de225a..55fbc89 100644 --- a/Assignment_028/solution/readme.md +++ b/Assignment_028/solution/readme.md @@ -1,5 +1,6 @@ # Lösung: Iteratoren auf Zahlen -
















































































```ruby + +```ruby 10.downto(0) { |n| puts n } ``` \ No newline at end of file diff --git a/Assignment_029/solution/readme.md b/Assignment_029/solution/readme.md index c0a6856..159af7b 100644 --- a/Assignment_029/solution/readme.md +++ b/Assignment_029/solution/readme.md @@ -1,5 +1,6 @@ # Lösung: Quine -
















































































```ruby + +```ruby p = "p = \"%s\"; puts p %% [ p.gsub(/[\"\\\\]/, '\"' => '\\\"', '\\\\' => '\\\\\\\\') ]"; puts p % [ p.gsub(/["\\]/, '"' => '\\"', '\\' => '\\\\') ] ``` \ No newline at end of file diff --git a/Assignment_030/solution/readme.md b/Assignment_030/solution/readme.md index d124c8b..3e01569 100644 --- a/Assignment_030/solution/readme.md +++ b/Assignment_030/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Reguläre Ausdrücke: Match -




























































```ruby + +```ruby def tag?(text) !!(/^<.*?>$/ =~ text) end diff --git a/Assignment_031/solution/readme.md b/Assignment_031/solution/readme.md index eb2ef8e..e677230 100644 --- a/Assignment_031/solution/readme.md +++ b/Assignment_031/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Reguläre Ausdrücke: Matching -




























































```ruby + +```ruby def reverser(s) /(.*) (.*)/ =~ s "#{$2} #{$1}" diff --git a/Assignment_032/solution/readme.md b/Assignment_032/solution/readme.md index 6611197..20babbd 100644 --- a/Assignment_032/solution/readme.md +++ b/Assignment_032/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Klassen per Reflection analysieren -
















































































```ruby + +```ruby def analyze(clazz) puts "Name: #{clazz.to_s}" puts "Elternklasse: #{clazz.superclass}" diff --git a/Assignment_033/solution/readme.md b/Assignment_033/solution/readme.md index 9794f52..0e57dd6 100644 --- a/Assignment_033/solution/readme.md +++ b/Assignment_033/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Methoden einer Klasse dynamisch erzeugen -
















































































```ruby + +```ruby def to_leet(s) s.tr('aeiou', '43107') end diff --git a/Assignment_034/solution/readme.md b/Assignment_034/solution/readme.md index 82fcc15..13d42e4 100644 --- a/Assignment_034/solution/readme.md +++ b/Assignment_034/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Klasse dynamisch erzeugen -
















































































```ruby + +```ruby def create_class(super_class) Class.new(super_class) do def who_am_i diff --git a/Assignment_035/solution/readme.md b/Assignment_035/solution/readme.md index adaa483..d00aba8 100644 --- a/Assignment_035/solution/readme.md +++ b/Assignment_035/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Methoden dynamisch aufrufen -
















































































```ruby + +```ruby def crazy_caller(obj) # Methoden suchen obj.methods.each do |m| diff --git a/Assignment_036/solution/readme.md b/Assignment_036/solution/readme.md index 9d87749..35974e1 100644 --- a/Assignment_036/solution/readme.md +++ b/Assignment_036/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Eigenclass einer Klasse -
















































































```ruby + +```ruby class Numeric class << self def to_binary(n) diff --git a/Assignment_037/solution/readme.md b/Assignment_037/solution/readme.md index 4e3d51e..cb47302 100644 --- a/Assignment_037/solution/readme.md +++ b/Assignment_037/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Eigenclass eines Objektes -
















































































```ruby + +```ruby s1 = "Hallo" s2 = "Welt" diff --git a/Assignment_038/solution/readme.md b/Assignment_038/solution/readme.md index bbd3801..175200b 100644 --- a/Assignment_038/solution/readme.md +++ b/Assignment_038/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Macro -
















































































```ruby + +```ruby module Javanator def Javanator::javafy def toString; to_s; end diff --git a/Assignment_039/solution/readme.md b/Assignment_039/solution/readme.md index 9573ba3..9191f15 100644 --- a/Assignment_039/solution/readme.md +++ b/Assignment_039/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Metaprogrammierung: Die kleine Petze -


















































```ruby + +```ruby class Snitch def method_missing(name, *args, **keywords, &block) puts "Aufruf von Methode '#{name}'" diff --git a/Assignment_040/solution/readme.md b/Assignment_040/solution/readme.md index 7d1d480..afb33fc 100644 --- a/Assignment_040/solution/readme.md +++ b/Assignment_040/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Singleton Methoden -
















































































```ruby + +```ruby s1 = "Hallo" s2 = "Welt" diff --git a/Assignment_041/solution/readme.md b/Assignment_041/solution/readme.md index ac39a0c..b14e2ec 100644 --- a/Assignment_041/solution/readme.md +++ b/Assignment_041/solution/readme.md @@ -1,6 +1,7 @@ # Lösung: Struct -
















































































```ruby + +```ruby # Klasse (sic!) über Struct erzeugen Studierender = Struct.new(:vorname, :nachname, :geboren, :matrikel, :fakultaet)