Best explanation of Ruby blocks? [closed]

I offer up my own explanation from this answer, slightly modified: “Blocks” in Ruby are not the same as the general programming terms “code block” or “block of code”. Pretend for a moment that the following (invalid) Ruby code actually worked: def add10( n ) puts “#{n} + 10 = #{n+10}” end def do_something_with_digits( method … Read more

Referring to weak self inside a nested block

Your code will work fine: the weak reference will not cause a retain cycle as you explicitly instruct ARC not to increase the retainCount of your weak object. For best practice, however, you should create a strong reference of your object using the weak one. This won’t create a retain cycle either as the strong … Read more

How to make text input box to occupy all the remaining width within parent block?

Updated [Oct 2016]: Flexbox version… form { display: flex; } form input[type=”text”] { flex: 1; } <form> <label>Name</label> <input type=”text” /> <button>Submit</button> </form> <p>Lorem ipsum…</p> Original answer [Apr 2011]: Table-less CSS version (of table behavior)… <div id=”parent”> <div id=”inner”> <label>Name</label> <span><input id=”text” type=”text” /></span> <input id=”submit” type=”button” value=”Submit” /> </div> <p>some paragraph text</p> </div> CSS… … Read more

How to center things – display:block/inline-block

Block elements should always be centered using .block { margin-left: auto; margin-right: auto; width: 600px; } as stated by the w3c: http://www.w3.org/Style/Examples/007/center.en.html#block text-align: center; is well-named: use it to center texts. Update You can also use display: flex now: .parent { display: flex; justify-content: center; } .block { width: 200px; }

optional closure and check if it is nil

You need to wrap your closure signature in parentheses to make the closure itself optional. The way it’s written now, the closure returns an optional Void (which doesn’t really make sense). var completionHandler: ((sucsess:Bool!, items:[AnyObject]!)->())? Some style points and revisions to your example code: // Capitalize class names so it’s clear what’s a class class … Read more