You will learn how to unlock the full power of the Ruby programming language to create your own applications. From basic things like strings, arrays & hashes to more advanced topics like blocks & multi-threading.
Make sure to subscribe now so you don't miss out on new videos!
Would've been great to mention that the merge method accepts a block to resolve conflicts between hashes. a = { bacon: 3, chocolate: 2, apple: 1 } b = { bacon: 1, chocolate: 1, banana: 1 } c = a.merge(b) { |key, old_val, new_val| old_val + new_val } p c # {:bacon=>4, :chocolate=>3, :apple=>1, :banana=>1}
Thanks man!! I wasted my whole day trying to make this work and this is the first tutorial that is useful. I need to make this with JS and Ajax, do u know if it is too different?
Good overview, but an important aspect of the strategy pattern that wasn't mentioned is that strategies can be switched at run-time / during execution. Adding an attr_reader :formatter to the Reporter class and updating the @formatter instance variable before calling Reporter#report would suffice to show this quality.
A question - how can you remove 'Last Page' and 'Next Page' on pages where there is no last page (the first page) and no next page (on the final page of results) - so it detects when there are no further books to paginate so it removes the option? Hope that makes sense!
That is a great question Sam! You'll need to use some logic statements to solve this. In other words, you need if statements to check if the next page would have more books on it or not, if it doesn't then you skip the ERB (or HAML, Slim, etc.) code for the "Next Page" section.