float= The Red Rook (cover).png

Parallel Visions: City of Angels City of Demons ebook and trade paperback available on Amazon (or here).
The question of whether Vance was dead or not became more than academic when he found himself in a bathtub up to his chin in ice water like some forgotten cocktail garnish, a demonic woman standing over him, and no memory of how he got there.
Read free chapters of Parallel Visions: City of Angels City of Demons here
The Red Rook, sequel to Dispensing Justice and the second novel of Nova Genesis World is now available for Kindle or as a paperback at Amazon.
Read free chapters of Dispensing Justice here (or get it here).
Read free chapters of The Red Rook here (or get it here). -- Fritz Freiheit

Dispensing Justice (cover).png 20th Annual Writer's Digest Self-Published Book Awards - Honorable Mention.png

Ruby code snippets

From FritzWiki
Jump to: navigation, search

Some useful Ruby code snippets

7 random characters 
('a'..'z').to_a.shuffle[0..7].join
create an object and assign value(s) then assign to variable 
obj = SomeClass.new.tap { |obj| obj.key = 'value' }
See: Ruby - #tap that!


Some interesting things to try in Rugy

pass by reference or pass by value test 
def foo(bar) bar = 'reference' end; baz = 'value'; foo(baz); puts "Ruby is pass-by-#{baz}"
as versus
def foo(bar) bar.replace 'reference' end; baz = 'value'; foo(baz); puts "Ruby is pass-by-#{baz}"
See: Is Ruby pass by reference or by value? - Stack Overflow

Code style notes

assignment to local variable in function call for clarity/documentation purposes
obj.func( some_flag = true )
(note: need to test this and/or find out about possible side effects)


Code Snippet

v • d • e