<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>globaldev</title>
    
    <link>http://globaldev.co.uk</link>
    <description>Global Personals Development Team</description>
    <lastBuildDate>Wed, 22 May 2013 08:05:21 -0700</lastBuildDate>
    <language>en</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>

    
      <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/globaldev" /><feedburner:info uri="globaldev" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
        <title>Ben is speaking at EuRuKo 2013</title>
        <pubDate>Sun, 19 May 2013 00:00:00 -0700</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/_Tp0ycdpMvI/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/05/ben-is-speaking-at-euruko-2013/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>Way back around the start of April this year I drafted a proposal for a talk I&amp;#8217;d begun preparing on Celluloid and JRuby. Mostly gleaned from my findings in applying both technologies to an innovative Global Dev scammer detection solution due to launch shortly on our White Label Dating platform.With...</description>
        <content:encoded><![CDATA[<img class='alignright' src='/images/uploads/2013/05/euruko.png' alt='EuRuKo 2013' />
<p>Way back around the start of April this year I drafted a proposal for a talk I&#8217;d begun preparing on <a href='http://celluloid.io'>Celluloid</a> and <a href='http://jruby.org'>JRuby</a>. Mostly gleaned from my findings in applying both technologies to an innovative Global Dev scammer detection solution due to launch shortly on our <a href='http://www.whitelabeldating.com/'>White Label Dating</a> platform.</p>

<p>With some trepidation I then submitted my proposal to the innovative <a href='http://euruko2013.org'>EuRuKo 2013</a> CfP. EuRuKo have this year chosen to employ the same CfP system as pioneered by the UK&#8217;s own <a href='http://rubymanor.org'>Ruby Manor</a> conference - <a href='https://github.com/rubymanor/vestibule'><em>Vestibule</em></a>.</p>
<img class='alignleft' src='/images/uploads/2013/05/celluloid.png' alt='Celluloid' />
<p><em>Vestibule</em> is an open source application for fielding anonymous conference proposals. The main premise being that anonymous proposals encourage inclusion, and a level playing field for potentially lesser-known speakers. Once a proposal is submitted, the community can help shape and refine the synopsis and points of discussion, all the while preserving anonymity of the originator.</p>

<p>EuRuKo&#8217;s process was phased into two rounds with progression through the process based on public voting, number of views, number of comments, social network mentions and refinements made throughout the process. You can see their <a href='http://cfp.euruko2013.org/about'>thorough explanation here</a>.</p>
<img class='alignright' src='/images/uploads/2013/05/jruby.png' alt='JRuby' />
<p>I was pleased to learn my proposal had made it through the first stage of over 90 initial submissions and into the shortlist of 30 proposals. Subsequently after a further voting round I learned my proposal had been ranked sixth by the community thus cementing my spot at EuRuko 2013! To think I&#8217;ll be sharing a stage with <a href='http://en.wikipedia.org/wiki/Yukihiro_Matsumoto'>Matz</a> - the creator of Ruby, is seriously scary and exciting in equal measure.</p>

<p>Hopefully I&#8217;ll see you in Athens, and I hope to both educate and entertain with my talk entitled: <em>Achieving zomgscale with Celluloid and JRuby</em></p>

<p>Thanks go out to Global Dev for sponsoring my attendance and making this possible.</p>

<p>If you&#8217;re a Ruby engineer, regardless if you&#8217;re an accomplished speaker or just a happy tinkerer, you could join us. <a href='/jobs'>We&#8217;re hiring</a> and have openings in both our Windsor and London offices. We will also happily consider remote positions for the right candidates. So <a href='/jobs'>get in touch!</a></p><img src="http://feeds.feedburner.com/~r/globaldev/~4/_Tp0ycdpMvI" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/05/ben-is-speaking-at-euruko-2013/</feedburner:origLink></item>
    
      <item>
        <title>Scottish Ruby Conference 2013</title>
        <pubDate>Sat, 18 May 2013 00:00:00 -0700</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/vlruRBebDZ8/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/05/scottish-ruby-conference-2013/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>Last weekend the Global Personals development team dispatched Barry, Tim, Mat, Steve and me to the Scottish Ruby Conference. Set in the absolutely stunning Crieff Hydro hotel complex - located in Perthshire in the Scottish highlands. Unfortunately, whilst we didn&amp;#8217;t get the opportunity to visit much of the surrounding area...</description>
        <content:encoded><![CDATA[<img class='alignright' src='/images/uploads/2013/05/scotruby.png' alt='Scottish Ruby 2013' />
<p>Last weekend the Global Personals development team dispatched <a href='http://twitter.com/barryf'>Barry</a>, <a href='http://twitter.com/timblair'>Tim</a>, <a href='http://twitter.com/matsadler'>Mat</a>, <a href='http://twitter.com/steviebuckley'>Steve</a> and me to the <a href='http://2013.scottishrubyconference.com/'>Scottish Ruby Conference</a>. Set in the absolutely stunning Crieff Hydro hotel complex - located in Perthshire in the Scottish highlands. Unfortunately, whilst we didn&#8217;t get the opportunity to visit much of the surrounding area we did manage to take in plenty of inspiration from the fantastic talks given throughout the conference.</p>

<p>Between the five of us we chose to strategically divide our time and attendance between almost all of the talks given during the two days and three simultaneous conference tracks. I also managed to squeeze in an off-the-cuff lightning format talk on <a href='http://celluloid.io/'>Celluloid</a> - a concurrent object oriented programming framework for ruby that lasted around five minutes and was well received. Also serving as sleight practice for my upcoming talk on <a href='http://euruko2013.org/speakers/'>Celluloid at Euruko 2013</a> - the European ruby conference in Athens.</p>

<p>I&#8217;ll briefly summarise the talks we attended during the conference, in roughly the order they were given:</p>

<h2 id='day_one'>Day One</h2>

<h3 id='keynote__rachel_meyers_on_growing_programming'>Keynote - Rachel Meyers on &#8220;Growing Programming&#8221;</h3>

<p>The conference kicked off in style with a personalised view of growing one&#8217;s skills as a programmer, and how we can shape the community to enable this. I can imagine sales figures for the SICP book peaked shortly after.</p>

<h3 id='james_edward_gray_ii_on_the_patterns_we_all_need_to_know'>James Edward Gray II on &#8220;The Patterns We All Need to Know&#8221;</h3>

<p>This talk presented a neat summation of the most regularly encountered patterns in the wild. It was great to see their application in idiomatic ruby, although unfortunately the slides featuring code were all but unreadable from a row or two back. Thankfully the slides were published shortly after.</p>

<h3 id='andr_arko_on_deathmatch_bundler_vs_rubygemsorg'>André Arko on &#8220;Deathmatch: Bundler vs. Rubygems.org&#8221;</h3>

<p>An interesting glance at the evolution of Bundler and Rubygems.org. Many of us will remember the early days of bundler and how much time was spent <em>Fetching source index</em>. This talk covered the incremental updates that Bundler and Rubygems.org received and the consequential performance gains.</p>

<h3 id='natalia_buckley_on_thinking_through_making'>Natalia Buckley on &#8220;Thinking through making&#8221;</h3>

<p>Natalia spends her time making. Making things. Making time for play. Making mistakes. It&#8217;s through this process of making that she learns. The most important thing I took away was to just get on and make. What you build doesn&#8217;t have to be perfect; it doesn&#8217;t even have to work. But through the process of making you learn, and the next time you&#8217;ll make something better.</p>

<h3 id='steve_klabnik_on_building_awesome_apis_with_railsapi'>Steve Klabnik on &#8220;Building awesome APIs with rails-api&#8221;</h3>

<p>A talk on the rails-api gem. A slimmed-down flavour of rails designed for serving performant and maintainable APIs. Rather than providing any specific guidance for building sane APIs this talk covered tools, gems and standards available to API developers.</p>

<h3 id='tekin_suleyman_on_bootstrapping_a_startup_a_developers_tale'>Tekin Suleyman on &#8220;Bootstrapping a Startup, a Developer&#8217;s Tale&#8221;</h3>

<p>3 years ago, Tekin had an idea. He spoke to a few people and decided it was worthwhile building. Over the course of the next 3 years he built crowd.fm as a side project, spending hundreds of hours on it. After all that work and time, he&#8217;s come to the conclusion that he&#8217;s built a solution to a problem that didn&#8217;t exist. A really interesting yet cautionary tale of what it takes to attempt to bootstrap a side project into a business.</p>

<h3 id='kevin_rutherford_on_telling_not_asking'>Kevin Rutherford on &#8220;Telling, not asking&#8221;</h3>

<p>This was Kevin&#8217;s take on the <em>Tell, don&#8217;t ask</em> principle and how it is commonly misunderstood and almost impossible to achieve in a modern rails codebase. Kevin detailed his approach, constructed of a simple message bus and <em>listeners</em> responding to application events. A pattern that is prevalent in more <em>enterprisey</em> languages but not so commonly found in ruby. Kevin had a very unique speaking style that was dry and ever-so humorous. An enjoyable and enlightening talk.</p>

<h3 id='chris_kelly_on_down_the_rb_newobj_rabbit_hole'>Chris Kelly on &#8220;Down the rb_newobj() Rabbit Hole&#8221;</h3>

<p>This talk had the potential to be quite a heavy subject to digest. Thankfully Chris guided us all the way down through MRI&#8217;s allocation implementation in a clear and concise style. In particular I found Chris&#8217;s slides to be very well presented. A thoroughly informative talk and one I personally found very thought provoking.</p>

<h3 id='erin_obrien_on_from_burning_desire_to_burning_out_how_to_prevent_the_fizzle'>Erin O&#8217;Brien on &#8220;From burning desire to burning out: How to prevent the fizzle&#8221;</h3>

<p>One of my favourite talks of the conference, Erin&#8217;s discussion of burn-out in developers was really eye-opening. She discussed the common signs of burn-out, and ways to attempt to handle it. With a background in psychology, she lent weight to her talk by backing everything up with research, but presented in an incredibly effective and accessible manner. Definitely worth the time to watch it when the video has been posted.</p>

<h3 id='jesse_toth_on_service_oriented_harmony'>Jesse Toth on &#8220;Service Oriented Harmony&#8221;</h3>

<p>Jesse presented a talk on her findings in the field when applying SOA architecture. It was an entertaining talk and resonated with much of our thinking at Global Personals since we apply SOA liberally. I do feel that Jesse somewhat side-stepped the principals and practices of testing, which to my mind is likely the most difficult concept to grasp in this field. However, this didn&#8217;t detract from the rest of the talk. I also learned shortly after that this was Jesse&#8217;s first time speaking publicly, which I would never have suspected.</p>

<h2 id='day_two'>Day Two</h2>

<h3 id='mike_moore_on_minitest__rails_total_bffs'>Mike Moore on &#8220;MiniTest &amp; Rails: Total BFFs&#8221;</h3>

<p>Mike&#8217;s talk on MiniTest 5 and integration with rails was very entertaining. I did feel it was pitched too high for me personally but it served as a great introduction for those not so familiar with the MiniTest framework. Bonus points must also be given for featuring My Little Ponies.</p>

<h3 id='kerri_miller_on_failure_for_fun_and_profit'>Kerri Miller on &#8220;Failure for Fun and Profit!&#8221;</h3>

<p>Kerri is someone who enjoys being a novice, and in this talk she ran us through the reasons why and how. Being a novice means you are constantly learning; learning means that you will generally be failing more often than not. She encouraged everyone to redefine failure from the big, nasty thing we generally think it is, but instead a necessary state before success. A really inspiring talk, with a bunch of awesome quotes, including &#8220;If you&#8217;re always achieving what you try, you&#8217;re only trying the achievable,&#8221; and &#8220;Good ideas come from experience; experience comes from bad ideas.&#8221;</p>

<h3 id='jim_weirich_on_given__designing_a_language'>Jim Weirich on &#8220;Given - Designing a Language&#8221;</h3>

<p>Having never seen Jim speak in person prior to this event I was very much looking forward to his talk on the <em>Given</em> testing DSL. I felt completely engrossed in Jim&#8217;s inimitable and highly conversational speaking style. <em>Given</em> is packed full of beautiful, idiomatic ruby tricks and I learned a few new ideas I can see myself applying to my own code in the future. I was especially impressed with the clean approach to re-raising errors and preserving their original backtraces.</p>

<h3 id='chris_parsons_on_leading_software_teams_well'>Chris Parsons on &#8220;Leading software teams well&#8221;</h3>

<p>The difference between management and leadership at first may seem like nothing more than an alternative word. Chris explained just how different the two things were: just because you&#8217;re a manager doesn&#8217;t make you a leader and, conversley, <em>anyone</em> can be a leader, no matter how junior. A lot to think about in how to lead teams, including snippets such as the perils of job titles: in Chris&#8217; experience they occasionally stopped people working on something, because it &#8220;wasn&#8217;t in their job title.&#8221;</p>

<h3 id='franck_verrot_on_be_wrong_but_try_things'>Franck Verrot on &#8220;Be Wrong, but try things&#8221;</h3>

<p>Franck&#8217;s talk was an eye-opener for me. I am a stickler for doing things <em>The Right Way</em>, and often agonise over a particular approach to a problem rather than experimenting with failure in the trial and error fashion. The talk was full of practical examples of failure leading to new understanding, particularly in the study of biology. An inspirational talk.</p>

<h3 id='mathias_meyer_on_cooking_infrastructure_with_chef'>Mathias Meyer on &#8220;Cooking Infrastructure with Chef&#8221;</h3>

<p>Mathias gave a high-level discussion on the benefits of infrastructure automation tools, focussing on Chef. He walked through the setup of the pieces of a basic infrastructure including application and database servers, and the deployment of these pieces into different environments.</p>

<h3 id='austin_vance_on_ruby_the_arduino_way'>Austin Vance on &#8220;Ruby the Arduino Way&#8221;</h3>

<p>Austin&#8217;s talk was a fun and light-hearted look at the arduino kit and how simple it can be to interface with ruby. Austin&#8217;s creation was a t-shirt firing cannon. Very well received and scheduled cleverly - occurring just prior to the closing keynote.</p>

<h3 id='closing_keynote__evan_henshawplath_on_ruby_history'>Closing Keynote - Evan Henshaw-Plath on &#8220;Ruby History&#8221;</h3>

<p>Evan&#8217;s talk detailed ruby&#8217;s progression from little-known and experimental, to the fully-fledged and immensely popular language it is today. The talk was humurous and very slick in it&#8217;s presentation. I felt it was the perfect end to a fantastic two days of conferencing.</p>

<h2 id='closing_thoughts'>Closing thoughts</h2>
<img class='alignleft' src='/images/uploads/2013/05/ben.jpg' alt='Ben Lovell - Celluloid Talk' />
<p>As ever, much of the valuable discussion was performed in the hallways. I met up with some old colleagues and acquaintances and so many rubyists of whom I was internet-familiar but had yet to meet in person. The setting was perfect, the catering fantastic and conference as a whole felt very slick. Credit must go to the organisers, and I will definitely return next year, although hopefully as a speaker.</p>

<p>Thanks go to Global Personals for sponsoring our attendance to the conference. Did I mention <a href='/jobs/'>we&#8217;re hiring?</a> ;)</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/vlruRBebDZ8" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/05/scottish-ruby-conference-2013/</feedburner:origLink></item>
    
      <item>
        <title>jQuery UK 2013 - A summary</title>
        <pubDate>Mon, 22 Apr 2013 00:00:00 -0700</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/fd9aYcojUEU/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/04/jquery-uk-2013-a-summary/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>IntroductionOn Friday a couple of us attended jQuery UK 2013 in Oxford. It&amp;#8217;s only the second time the conference has been held, and from what I could gather it was far larger this time around. The day started really well, with signposts and &amp;#8220;white rabbit&amp;#8221; paw prints leading the way...</description>
        <content:encoded><![CDATA[<img class='alignright' src='/images/uploads/2013/04/jquk-jabberwocky.jpg' alt='jQuery UK Jabberwocky' />
<h2 id='introduction'>Introduction</h2>

<p>On Friday a couple of us attended jQuery UK 2013 in Oxford. It&#8217;s only the second time the conference has been held, and from what I could gather it was far larger this time around. The day started really well, with signposts and &#8220;white rabbit&#8221; paw prints leading the way to the venue right from the station. The theme of the conference was Alice in Wonderland (hence the rabbit prints) and the sponsor hall came complete with a giant <a href='http://en.wikipedia.org/wiki/Jabberwocky'>jabberwocky</a>.</p>

<p>After coffee and pastries it was soon time to get started. Everyone piled in to the main room and started tweeting dubious jokes as soon as they realised there was a live Twitter wall on the right of the stage. The lack of wifi was a hot topic, but it wasn&#8217;t much of an issue. <a href='http://twitter.com/johnwards'>John Wards</a> of <a href='http://www.whiteoctober.co.uk/'>White October</a>, the conference organisers, kicked things off with a short introduction and then handed over to Brendan Eich, who, being the creator of JavaScript, understandably received a great reception.</p>

<h2 id='brendan_eich'>Brendan Eich</h2>

<p>Brendan&#8217;s talk focussed mainly on features of the upcoming ECMAScript 6, and the future ES7. There was a lot of interesting content, although not a huge amount of new information for people who keep up to date with <a href='https://mail.mozilla.org/listinfo/es-discuss'>es-discuss</a> regularly.</p>
<img class='alignleft' src='/images/uploads/2013/04/jquk-brendan-eich.jpg' alt='Brendan Eich' />
<p>A couple of demos of the Unreal engine, compiled to JavaScript, running in the browser with WebGL got an understandably excited reaction. The power of <a href='https://github.com/kripken/emscripten'>Emscripten</a> and <a href='http://asmjs.org/'>asm.js</a> looks absolutely amazing and is definitely something to keep an eye on over the next year or so. You can read more about that on the <a href='https://blog.mozilla.org/blog/2013/03/27/mozilla-is-unlocking-the-power-of-the-web-as-a-platform-for-gaming/'>Mozilla blog</a>, and I highly recommend you watch the very impressive videos.</p>

<p>Brendan also showed off his bright orange mobile phone and mentioned that the first developer preview <a href='http://www.mozilla.org/en-GB/firefox/partners/'>Firefox OS</a> devices will be available soon from <a href='http://www.geeksphone.com/'>Geeksphone</a>.</p>

<p>Next up was <a href='https://twitter.com/rworth'>Richard D. Worth</a>, executive director of the jQuery foundation.</p>

<h2 id='richard_d_worth'>Richard D. Worth</h2>

<p>Richard&#8217;s talk, &#8220;jQuery 1.9 and 2.0 - Present and Future&#8221;, gave us some great insights into the direction of the jQuery project. He started with some impressive statistics, pointing out that <strong>91.2%</strong> of the websites that use JavaScript use jQuery. That&#8217;s a huge number, far higher than I would have guessed.</p>

<p>He also confirmed the dropping of support for Internet Explorer 8 and below in jQuery 2.0, and made it clear that the team will continue to maintain the 1.9 branch, guaranteeing an API match between 1.x and 2.x as of 1.10. There was also confirmation of the new modular build system for 2.0, which means you are free to customise your copy of jQuery to suit your needs. For example, if you&#8217;re only targeting newer environments with <code>querySelectorAll</code> support, you can leave out Sizzle completely.</p>

<p>After Richard there was time for a short break before moving on to <a href='https://twitter.com/rem'>Remy Sharp</a>.</p>

<h2 id='remy_sharp'>Remy Sharp</h2>

<p>For a jQuery conference, <a href='https://speakerdeck.com/rem/i-know-jquery-now-what'>Remy&#8217;s talk</a> about why <em>not</em> to use jQuery sounded like it might be a little out of place, but actually turned out great. He explained why we shouldn&#8217;t rely upon jQuery for everything when native JavaScript and DOM methods can often achieve the same effect in the same amount of code.</p>
<img class='alignright' src='/images/uploads/2013/04/jquk-remy-cat.jpg' alt='Slide by Remy Sharp' />
<p>A lot of his points are even more valid with the release of jQuery 2.0. If you&#8217;re only supporting modern environments there is no reason to not start using, for example, native ES5 array methods such as <code>Array.prototype.forEach</code> instead of <code>jQuery.each</code>, and CSS3 animations instead of jQuery UI.</p>

<p>He introduced a new open source project, <a href='https://github.com/remy/min.js'>min.js</a>, aimed at providing a barebones jQuery-compatible API that simply wraps native DOM methods. It could be a useful tool for anyone aiming to strip jQuery out of projects that only need to work in newer browsers.</p>

<p>Next to take to the stage was <a href='https://twitter.com/ajpiano'>Adam J. Sontag</a>.</p>

<h2 id='adam_j_sontag'>Adam J. Sontag</h2>

<p>Having never seen a talk by Adam before, <a href='http://ajpiano.com/jquery-is-a-swiss-army-knife/#1'>this one</a> was definitely one of my highlights. He&#8217;s a hugely entertaining speaker. The talk was pretty much contradictory to Remy&#8217;s, explaining that &#8220;jQuery is a Swiss Army knife and that&#8217;s OK&#8221;. He pointed out that jQuery was his &#8220;gateway drug&#8221; to JavaScript, something which a lot of people in the room could relate to, and a very good reason to stop criticising people who use it. He finished up with a brilliant rebuttal of the common &#8220;jQuery is too big&#8221; argument. &#8220;jQuery is gigantic&#8230; you know what else is gigantic? JPEGs!&#8221;.</p>

<p>After Adam&#8217;s talk there was time for <a href='http://twitter.com/dougneiner'>Doug Neiner</a> before lunch.</p>

<h2 id='doug_neiner'>Doug Neiner</h2>

<p>I was looking forward to <a href='http://code.dougneiner.com/presentations/machina/'>Doug&#8217;s talk</a> in particular. It was all about finite state machines in JavaScript with <a href='https://github.com/ifandelse/machina.js'>Machina.js</a>. Unfortunately for Doug he seemed to be suffering from a bit of a sore throat and was quite squeaky throughout.</p>
<img class='alignleft' src='/images/uploads/2013/04/jquk-doug-neiner.jpg' alt='Doug Neiner' />
<p>He gave a good introduction to finite state machines in JavaScript with an excellent analogy to the transmission in a car, and demonstrated how the code to model this could quickly get messy. He then introduced Machina and showed how it can make the previous example much cleaner, before moving on to a real-world online/offline state example.</p>

<p>Overall, Doug&#8217;s talk was excellent and packed with decent example code. There&#8217;s too much of it to talk about here so I highly recommend you take a look through <a href='http://code.dougneiner.com/presentations/machina/'>his slides</a>.</p>

<h2 id='lunch'>Lunch</h2>

<p>Next up was a break for lunch, with loads of free food, Red Bull, and a giant cake provided by White October for their 10th anniversary. The live Twitter wall was back online, so cue many more poor jokes. Tweets containing script tags seemed to be a favourite, just to make sure the organisers were properly sanitising user input!</p>
<img class='alignright' src='/images/uploads/2013/04/jquk-cake.jpg' alt='Cake' />
<p>By this point, the <a href='http://www.youtube.com/watch?v=j0h2u87JwyA'>one song</a> that had been playing on repeat during all the intervals was definitely starting to become annoying!</p>

<p>The lunch break also featured a set of short &#8220;rising stars&#8221; talks, by upcoming speakers. Unfortunately, I didn&#8217;t get a chance to see any of these but by all accounts they were pretty good.</p>

<h2 id='garann_means'>Garann Means</h2>

<p>After the break, <a href='http://twitter.com/garannm'>Garann Means</a> talked about developing full-stack applications in JavaScript with Node, jQuery, websockets and MVC, with a focus on events.</p>

<p>This talk was interesting to us since we have been taking a similar approach with a lot of our JavaScript tools and libraries recently here at <a href='http://globalpersonals.co.uk/'>Global Personals</a>.</p>

<p>Following Garann was <a href='http://twitter.com/igrigorik'>Ilya Grigorik</a>, Web Performance Engineer at Google.</p>

<h2 id='ilya_grigorik'>Ilya Grigorik</h2>

<p>For me, <a href='https://docs.google.com/a/globalpersonals.co.uk/presentation/d/1DNljLkRpe9LIDfcqcpHzdLvEOyuVH4d1y9dtAJBr1I8/preview'>Ilya&#8217;s talk</a> was the highlight of the day. The title, &#8220;Wait, Chrome DevTools can do THAT?&#8221; didn&#8217;t suggest anything particularly exciting, but I learned so much from it. Again, there&#8217;s so much to cover that I can&#8217;t fit it in here, but watch out for a follow-up post when we&#8217;ve spent a bit of time playing around with all the new Chrome DevTools features.</p>

<p>He started with a reminder of <a href='https://www.google.co.uk/intl/en/chrome/browser/canary.html'>Chrome Canary</a>, and by the look of Twitter since this was a good idea since there were a surprising number of people unaware of it. There was also a really useful link to <a href='http://www.codeschool.com/courses/discover-devtools'>Code School lessons</a> on DevTools.</p>

<p>Highlights of the talk included custom themes and panels, remote mobile debugging and HAR exports. I can&#8217;t recommend this talk highly enough, so check out the <a href='https://docs.google.com/a/globalpersonals.co.uk/presentation/d/1DNljLkRpe9LIDfcqcpHzdLvEOyuVH4d1y9dtAJBr1I8/preview'>slides</a>. After another short break, <a href='http://twitter.com/johnbender'>John Bender</a> was up next.</p>

<h2 id='john_bender'>John Bender</h2>

<p>John is a member of the jQuery mobile team and the co-creator of <a href='http://vagrantup.com/'>Vagrant</a>. His talk was about improving the speed of DOM manipulation with jQuery by applying ideas from category theory.</p>
<img class='alignleft' src='/images/uploads/2013/04/jquk-john-bender.jpg' alt='John Bender' />
<p>The talk was fairly maths-heavy but relatively easy to follow and included some really interesting ideas. I, along with many of the other attendees, had never really considered the application of mathematical models to something like jQuery and the DOM.</p>

<p>John also introduced <a href='https://github.com/johnbender/wield'>Wield</a>, a small library developed out of many of the ideas presented in his talk, designed to abstract the collections and DOM manipulation APIs of jQuery and offer improved performance. It&#8217;s definitely worth checking out.</p>

<p>After that we moved on to <a href='http://twitter.com/Joe8Bit'>Joe Pettersson</a>, interaction designer and UI engineer.</p>

<h2 id='joe_pettersson'>Joe Pettersson</h2>

<p>Joe talked about testing, with a big focus on legacy versions of Internet Explorer. We were reminded of the <a href='http://www.modern.ie/en-us'>IE VMs</a> now available from Microsoft and showed how you can use tools such as <a href='http://jenkins-ci.org/'>Jenkins</a> and <a href='http://docs.seleniumhq.org/'>Selenium</a> to automate browser testing across virtual machines communicating with a central hub.</p>
<img class='alignright' src='/images/uploads/2013/04/jquk-joe-pettersson.jpg' alt='Joe Pettersson' />
<p>There were some really useful ideas in this talk, especially since this is something we are currently looking at implementing here. Joe&#8217;s sentiment of wanting to &#8220;stab the JScript engine with a fork&#8221; was shared by many. This talk was the penultimate session of the day and we moved on to <a href='http://twitter.com/JsonScott'>Jason Scott</a>, a jQuery mobile team member at BlackBerry.</p>

<h2 id='jason_scott'>Jason Scott</h2>

<p>In the final talk of the day, Jason explained the virtues of building an experience for your users rather than &#8220;just another framework&#8221;. He showed us how BlackBerry leverage the power of jQuery mobile to create better user experiences, including a demo of a custom <a href='https://github.com/jasondscott/jQueryMobile-BB10-Theme'>jQuery mobile theme</a> designed to mimic the native BlackBerry 10 interface.</p>

<h2 id='after_party'>After party</h2>

<p>And with that we were done! Everyone moved back into the sponsor hall for jBeery, a jQuery-inspired beer festival featuring various rebranded local ales and more good food. This was an ingenious idea and it seems like everyone had a brilliant evening. Who wouldn&#8217;t when there&#8217;s free beer all night? I stayed around for most of the night and chatted to some really interesting people.</p>

<p>Overall, I thoroughly enjoyed jQuery UK 2013 and would like to thank White October and John Wards for putting on such a brilliant event. Let&#8217;s hope for more of the same next year.</p>
<img class='alignleft' src='/images/uploads/2013/04/jquk-burrito.jpg' alt='Burritos' /><img class='alignleft' src='/images/uploads/2013/04/jquk-beer.jpg' alt='Beer' /><img src="http://feeds.feedburner.com/~r/globaldev/~4/fd9aYcojUEU" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/04/jquery-uk-2013-a-summary/</feedburner:origLink></item>
    
      <item>
        <title>Ruby 2.0.0 in Detail</title>
        <pubDate>Tue, 12 Mar 2013 00:00:00 -0700</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/ApGgzP9XYQs/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/03/ruby-2-0-0-in-detail/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>Following on from our preview of the new features in Ruby 2.0.0, that version has now been officially released, so here&amp;#8217;s a thorough and detailed run-down of all the tweaks, changes and additions that have made it in to the release.Keyword argumentsdef wrap(string, before: &amp;quot;&amp;lt;&amp;quot;, after: &amp;quot;&amp;gt;&amp;quot;) &amp;quot;#{before}#{string}#{after}&amp;quot; # no...</description>
        <content:encoded><![CDATA[<p>Following on from our <a href='/2012/11/ruby-2-0-0-preview-features/'>preview</a> of the new features in Ruby 2.0.0, that version has now been officially released, so here&#8217;s a thorough and detailed run-down of all the tweaks, changes and additions that have made it in to the release.</p>

<h2 id='keyword_arguments'>Keyword arguments</h2>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>wrap</span><span class='p'>(</span><span class='n'>string</span><span class='p'>,</span> <span class='ss'>before</span><span class='p'>:</span> <span class='s2'>&quot;&lt;&quot;</span><span class='p'>,</span> <span class='ss'>after</span><span class='p'>:</span> <span class='s2'>&quot;&gt;&quot;</span><span class='p'>)</span>
  <span class='s2'>&quot;</span><span class='si'>#{</span><span class='n'>before</span><span class='si'>}#{</span><span class='n'>string</span><span class='si'>}#{</span><span class='n'>after</span><span class='si'>}</span><span class='s2'>&quot;</span> <span class='c1'># no need to retrieve options from a hash</span>
<span class='k'>end</span>

<span class='c1'># optional</span>
<span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>)</span>                                  <span class='c1'>#=&gt; &quot;&lt;foo&gt;&quot;</span>
<span class='c1'># one or the other</span>
<span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>before</span><span class='p'>:</span> <span class='s2'>&quot;#&lt;&quot;</span><span class='p'>)</span>                    <span class='c1'>#=&gt; &quot;#&lt;foo&gt;&quot;</span>
<span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>after</span><span class='p'>:</span> <span class='s2'>&quot;]&quot;</span><span class='p'>)</span>                      <span class='c1'>#=&gt; &quot;&lt;foo]&quot;</span>
<span class='c1'># order not important</span>
<span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>after</span><span class='p'>:</span> <span class='s2'>&quot;]&quot;</span><span class='p'>,</span> <span class='ss'>before</span><span class='p'>:</span> <span class='s2'>&quot;[&quot;</span><span class='p'>)</span>         <span class='c1'>#=&gt; &quot;[foo]&quot;</span>
</code></pre></div>
<p>One of the nice things about this compared to hash-as-fake-keyword-args is that it errors when you make a mistake.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>begin</span>
  <span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>befoer</span><span class='p'>:</span> <span class='s2'>&quot;#&lt;&quot;</span><span class='p'>)</span>
<span class='k'>rescue</span> <span class='no'>ArgumentError</span> <span class='o'>=&gt;</span> <span class='n'>e</span>
  <span class='n'>e</span><span class='o'>.</span><span class='n'>message</span>                                  <span class='c1'>#=&gt; &quot;unknown keyword: befoer&quot;</span>
<span class='k'>end</span>
</code></pre></div>
<p>You can use double splat to capture all keyword arguments, just like a single splat to capture all regular arguments. You can also use the double splat to unpack a hash to keyword arguments.</p>
<div class='highlight'><pre><code class='ruby'><span class='c1'># arguments</span>
<span class='k'>def</span> <span class='nf'>capture</span><span class='p'>(</span><span class='o'>**</span><span class='n'>opts</span><span class='p'>)</span>
  <span class='n'>opts</span>
<span class='k'>end</span>
<span class='n'>capture</span><span class='p'>(</span><span class='ss'>foo</span><span class='p'>:</span> <span class='s2'>&quot;bar&quot;</span><span class='p'>)</span>                          <span class='c1'>#=&gt; {:foo=&gt;&quot;bar&quot;}</span>

<span class='c1'># keys must be symbols</span>
<span class='n'>opts</span> <span class='o'>=</span> <span class='p'>{</span><span class='ss'>:before</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;(&quot;</span><span class='p'>,</span> <span class='ss'>:after</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;)&quot;</span><span class='p'>}</span>
<span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='o'>**</span><span class='n'>opts</span><span class='p'>)</span>                          <span class='c1'>#=&gt; &quot;(foo)&quot;</span>
</code></pre></div>
<p>The old hash style syntax is still accepted for keyword arguments, so you can update your method definitions without having to fix all the callers.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>:before</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;{&quot;</span><span class='p'>,</span> <span class='ss'>:after</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;}&quot;</span><span class='p'>)</span>   <span class='c1'>#=&gt; &quot;{foo}&quot;</span>
</code></pre></div>
<p>If you&#8217;re writing a library that needs to be compatible across ruby 2.0 and 1.9 the old hash-as-fake-keyword-args trick still works, and can be called as if it was using keyword arguments</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>wrap</span><span class='p'>(</span><span class='n'>string</span><span class='p'>,</span> <span class='n'>opts</span><span class='o'>=</span><span class='p'>{})</span>
  <span class='n'>before</span> <span class='o'>=</span> <span class='n'>opts</span><span class='o'>[</span><span class='ss'>:before</span><span class='o'>]</span> <span class='o'>||</span> <span class='s2'>&quot;&lt;&quot;</span>
  <span class='n'>after</span> <span class='o'>=</span> <span class='n'>opts</span><span class='o'>[</span><span class='ss'>:after</span><span class='o'>]</span> <span class='o'>||</span> <span class='s2'>&quot;&gt;&quot;</span>
  <span class='s2'>&quot;</span><span class='si'>#{</span><span class='n'>before</span><span class='si'>}#{</span><span class='n'>string</span><span class='si'>}#{</span><span class='n'>after</span><span class='si'>}</span><span class='s2'>&quot;</span>
<span class='k'>end</span>

<span class='n'>wrap</span><span class='p'>(</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>before</span><span class='p'>:</span> <span class='s2'>&quot;[&quot;</span><span class='p'>,</span> <span class='ss'>after</span><span class='p'>:</span> <span class='s2'>&quot;]&quot;</span><span class='p'>)</span>         <span class='c1'>#=&gt; &quot;[foo]&quot;</span>
</code></pre></div>
<h2 id='_and__symbol_array_literal'><code>%i</code> and <code>%I</code> symbol array literal</h2>
<div class='highlight'><pre><code class='ruby'><span class='o'>%</span><span class='n'>i</span><span class='p'>{</span><span class='n'>an</span> <span class='n'>array</span> <span class='n'>of</span> <span class='n'>symbols</span><span class='p'>}</span>   <span class='c1'>#=&gt; [:an, :array, :of, :symbols]</span>
</code></pre></div>
<p>and with interpolation</p>
<div class='highlight'><pre><code class='ruby'><span class='o'>%</span><span class='n'>I</span><span class='p'>{</span><span class='c1'>#{1 + 1}x #{2 + 2}x}   #=&gt; [:&quot;2x&quot;, :&quot;4x&quot;]</span>
</code></pre></div>
<h2 id='refinements'>Refinements</h2>

<p>Refinements is a neat idea, but the original implementation came with a weird edge cases and possible performance penalties, so what we get with Ruby 2.0.0 is a rather scaled back, and slightly less useful version of the original.</p>

<p>You create a refinement to a class, name spaced inside a module</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>module</span> <span class='nn'>NumberQuery</span>
  <span class='n'>refine</span> <span class='nb'>String</span> <span class='k'>do</span>
    <span class='k'>def</span> <span class='nf'>number?</span>
      <span class='n'>match</span><span class='p'>(</span><span class='sr'>/\A[1-9][0-9]*\z/</span><span class='p'>)</span> <span class='p'>?</span> <span class='kp'>true</span> <span class='p'>:</span> <span class='kp'>false</span>
    <span class='k'>end</span>
  <span class='k'>end</span>
<span class='k'>end</span>
</code></pre></div>
<p>this refinement isn&#8217;t visible by default</p>
<div class='highlight'><pre><code class='ruby'><span class='s2'>&quot;123&quot;</span><span class='o'>.</span><span class='n'>respond_to?</span><span class='p'>(</span><span class='ss'>:number?</span><span class='p'>)</span>   <span class='c1'>#=&gt; false</span>
</code></pre></div>
<p>once you declare that you are <code>using</code> the module with the refinement, then it becomes visible.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>using</span> <span class='no'>NumberQuery</span>
<span class='s2'>&quot;123&quot;</span><span class='o'>.</span><span class='n'>number?</span>                 <span class='c1'>#=&gt; true</span>
</code></pre></div>
<p>however <code>using</code> is only available at the top level, and only applies to lines after it in the same source file it&#8217;s declared. You also get a warning that refinements are experimental if you&#8217;re running with warnings enabled.</p>

<h2 id='id4'><code>Module#prepend</code></h2>

<p>Module gains <code>#prepend</code> as a compliment to <code>#include,</code> it works just like <code>include,</code> but it inserts the module in to the inheritance chain as if it were a subclass rather than a superclass.</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Object</span>
<span class='n'>superclass</span>
<span class='n'>included</span> <span class='k'>module</span>
<span class='nn'>class</span>
<span class='n'>prepended</span> <span class='n'>module</span>
</code></pre></div>
<p>This takes over from Rails&#8217; <code>#alias_method_chain</code> or the trick of aliasing a method to a new name before redefining it and calling the original.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='k'>def</span> <span class='nf'>do_stuff</span>
    <span class='nb'>puts</span> <span class='s2'>&quot;doing stuff&quot;</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='k'>module</span> <span class='nn'>Wrapper</span>
  <span class='k'>def</span> <span class='nf'>do_stuff</span>
    <span class='nb'>puts</span> <span class='s2'>&quot;before stuff&quot;</span>
    <span class='k'>super</span>
    <span class='nb'>puts</span> <span class='s2'>&quot;after stuff&quot;</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='n'>prepend</span> <span class='no'>Wrapper</span>
<span class='k'>end</span>

<span class='no'>Foo</span><span class='o'>.</span><span class='n'>new</span><span class='o'>.</span><span class='n'>do_stuff</span>
</code></pre></div>
<p>outputs:</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>before</span> <span class='n'>stuff</span>
<span class='n'>doing</span> <span class='n'>stuff</span>
<span class='n'>after</span> <span class='n'>stuff</span>
</code></pre></div>
<p>there&#8217;s also <code>::prepended</code> and <code>::prepend_features</code> method that work like <code>::included</code> and <code>::append_features</code></p>

<h2 id='unbound_methods_from_a_module_can_be_bound_to_any_object'>Unbound methods from a module can be bound to any object</h2>

<p>This one might sound like gibberish, or some minor change to something you&#8217;ll never use, but it&#8217;s actually a really great new feature.</p>

<p>You can get ahold of a method object from any class or module, with <code>instance_method</code></p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Object</span><span class='o'>.</span><span class='n'>instance_method</span><span class='p'>(</span><span class='ss'>:to_s</span><span class='p'>)</span>   <span class='c1'>#=&gt; #&lt;UnboundMethod: Object(Kernel)#to_s&gt;</span>
</code></pre></div>
<p>However, this method isn&#8217;t bound to anything, it has no <code>self</code>, and can&#8217;t be called. To call it you have to bind the method to an object, but methods have to be bound to an object of the same class as the one the method was taken from.</p>

<p>But now we can take a method from a module and bind it to any object</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>module</span> <span class='nn'>Bar</span>
  <span class='k'>def</span> <span class='nf'>bar</span>
    <span class='s2'>&quot;bar&quot;</span>
  <span class='k'>end</span>
  <span class='k'>def</span> <span class='nf'>baz</span>
    <span class='s2'>&quot;baz&quot;</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='no'>Bar</span><span class='o'>.</span><span class='n'>instance_method</span><span class='p'>(</span><span class='ss'>:bar</span><span class='p'>)</span><span class='o'>.</span><span class='n'>bind</span><span class='p'>(</span><span class='no'>Object</span><span class='o'>.</span><span class='n'>new</span><span class='p'>)</span><span class='o'>.</span><span class='n'>call</span>   <span class='c1'>#=&gt; &quot;bar&quot;</span>
</code></pre></div>
<p>This means <code>define_method</code> also accepts unbound methods for modules, which will let us implement a selective <code>include</code></p>
<div class='highlight'><pre><code class='ruby'><span class='k'>module</span> <span class='nn'>Kernel</span>
  <span class='k'>def</span> <span class='nf'>from</span><span class='p'>(</span><span class='n'>mod</span><span class='p'>,</span> <span class='kp'>include</span><span class='p'>:</span> <span class='o'>[]</span><span class='p'>)</span>
    <span class='k'>raise</span> <span class='no'>TypeError</span><span class='p'>,</span> <span class='s2'>&quot;argument must be a module&quot;</span> <span class='k'>unless</span> <span class='no'>Module</span> <span class='o'>===</span> <span class='n'>mod</span>
    <span class='kp'>include</span><span class='o'>.</span><span class='n'>each</span> <span class='k'>do</span> <span class='o'>|</span><span class='nb'>name</span><span class='p'>,</span> <span class='n'>original</span><span class='o'>|</span>
      <span class='n'>define_method</span><span class='p'>(</span><span class='nb'>name</span><span class='p'>,</span> <span class='n'>mod</span><span class='o'>.</span><span class='n'>instance_method</span><span class='p'>(</span><span class='n'>original</span> <span class='o'>||</span> <span class='nb'>name</span><span class='p'>))</span>
    <span class='k'>end</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='n'>from</span> <span class='no'>Bar</span><span class='p'>,</span> <span class='kp'>include</span><span class='p'>:</span> <span class='p'>{</span><span class='ss'>:qux</span> <span class='o'>=&gt;</span> <span class='ss'>:bar</span><span class='p'>}</span>
<span class='k'>end</span>

<span class='n'>f</span> <span class='o'>=</span> <span class='no'>Foo</span><span class='o'>.</span><span class='n'>new</span>
<span class='n'>f</span><span class='o'>.</span><span class='n'>qux</span>                 <span class='c1'>#=&gt; &quot;bar</span>
<span class='n'>f</span><span class='o'>.</span><span class='n'>respond_to?</span><span class='p'>(</span><span class='ss'>:baz</span><span class='p'>)</span>   <span class='c1'>#=&gt; false</span>
</code></pre></div>
<h2 id='_understands_namespaces'><code>const_get</code> understands namespaces</h2>
<div class='highlight'><pre><code class='ruby'><span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='k'>module</span> <span class='nn'>Bar</span>
    <span class='no'>Baz</span> <span class='o'>=</span> <span class='mi'>1</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='no'>Object</span><span class='o'>.</span><span class='n'>const_get</span><span class='p'>(</span><span class='s2'>&quot;Foo::Bar::Baz&quot;</span><span class='p'>)</span>   <span class='c1'>#=&gt; 1</span>
</code></pre></div>
<h2 id='_as_standard_for_convert_to_hash'><code>#to_h</code> as standard for &#8216;convert to hash&#8217;</h2>

<p><code>Hash</code>, along with <code>ENV</code>, <code>nil</code>, <code>Struct</code>, and <code>OpenStruct</code> all get a <code>#to_h</code> method which returns a hash</p>
<div class='highlight'><pre><code class='ruby'><span class='p'>{</span><span class='ss'>:foo</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;bar&quot;</span><span class='p'>}</span><span class='o'>.</span><span class='n'>to_h</span>               <span class='c1'>#=&gt; {:foo=&gt;&quot;bar&quot;}</span>
<span class='kp'>nil</span><span class='o'>.</span><span class='n'>to_h</span>                           <span class='c1'>#=&gt; {}</span>
<span class='no'>Struct</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='ss'>:foo</span><span class='p'>)</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='s2'>&quot;bar&quot;</span><span class='p'>)</span><span class='o'>.</span><span class='n'>to_h</span>   <span class='c1'>#=&gt; {:foo=&gt;&quot;bar&quot;}</span>
<span class='nb'>require</span> <span class='s2'>&quot;ostruct&quot;</span>
<span class='nb'>open</span> <span class='o'>=</span> <span class='no'>OpenStruct</span><span class='o'>.</span><span class='n'>new</span>
<span class='nb'>open</span><span class='o'>.</span><span class='n'>foo</span> <span class='o'>=</span> <span class='s2'>&quot;bar&quot;</span>
<span class='nb'>open</span><span class='o'>.</span><span class='n'>to_h</span>                          <span class='c1'>#=&gt; {:foo=&gt;&quot;bar&quot;}</span>
</code></pre></div>
<p>There is also a <code>Hash()</code> method, like <code>Array()</code>, that delegates to <code>#to_h</code></p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Hash</span><span class='p'>({</span><span class='ss'>:foo</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;bar&quot;</span><span class='p'>})</span>              <span class='c1'>#=&gt; {:foo=&gt;&quot;bar&quot;}</span>
<span class='no'>Hash</span><span class='p'>(</span><span class='kp'>nil</span><span class='p'>)</span>                          <span class='c1'>#=&gt; {}</span>
</code></pre></div>
<h2 id='_and_'><code>Array#bsearch</code> and <code>Range#bsearch</code></h2>

<p>Array and Range get a binary search method with <code>#bsearch</code>. This has two modes of working, find-minimum and find-any. Both modes take a block, and the array will have to be sorted with regards to this block.</p>

<p>In find-minimum mode it will return the first element greater than or equal to a chosen value. To use this mode you supply a block that returns true when the supplied element is greater than or equal to the chosen value, and false otherwise.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>array</span> <span class='o'>=</span> <span class='o'>[</span><span class='mi'>2</span><span class='p'>,</span> <span class='mi'>4</span><span class='p'>,</span> <span class='mi'>8</span><span class='p'>,</span> <span class='mi'>16</span><span class='p'>,</span> <span class='mi'>32</span><span class='o'>]</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='n'>x</span> <span class='o'>&gt;=</span> <span class='mi'>4</span><span class='p'>}</span>       <span class='c1'>#=&gt; 4</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='n'>x</span> <span class='o'>&gt;=</span> <span class='mi'>7</span><span class='p'>}</span>       <span class='c1'>#=&gt; 8</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='n'>x</span> <span class='o'>&gt;=</span> <span class='mi'>9</span><span class='p'>}</span>       <span class='c1'>#=&gt; 16</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='n'>x</span> <span class='o'>&gt;=</span> <span class='mi'>0</span><span class='p'>}</span>       <span class='c1'>#=&gt; 2</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='n'>x</span> <span class='o'>&gt;=</span> <span class='mi'>33</span><span class='p'>}</span>      <span class='c1'>#=&gt; nil</span>
</code></pre></div>
<p>In find any mode you need to supply a block that returns a positive number if the supplied element is less than your chosen value, a negative number if it is greater, and 0 if it is the chosen value.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='mi'>4</span> <span class='o'>&lt;=&gt;</span> <span class='n'>x</span><span class='p'>}</span>      <span class='c1'>#=&gt; 4</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='mi'>7</span> <span class='o'>&lt;=&gt;</span> <span class='n'>x</span><span class='p'>}</span>      <span class='c1'>#=&gt; nil</span>
</code></pre></div>
<p>Your block can return <code>0</code> for a range of values, in which case any of them may be chosen.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>array</span> <span class='o'>=</span> <span class='o'>[</span><span class='mi'>0</span><span class='p'>,</span> <span class='mi'>4</span><span class='p'>,</span> <span class='mi'>7</span><span class='p'>,</span> <span class='mi'>10</span><span class='p'>,</span> <span class='mi'>12</span><span class='o'>]</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>map</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='mi'>1</span> <span class='o'>-</span> <span class='n'>x</span> <span class='o'>/</span> <span class='mi'>4</span> <span class='p'>}</span>       <span class='c1'>#=&gt; [1, 0, 0, -1, -2]</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>bsearch</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='mi'>1</span> <span class='o'>-</span> <span class='n'>x</span> <span class='o'>/</span> <span class='mi'>4</span> <span class='p'>}</span>   <span class='c1'>#=&gt; 4 or 7</span>
</code></pre></div>
<h2 id='id5'><code>Enumerable#lazy</code></h2>

<p><code>#lazy</code> called on any <code>Enumerable</code> (<code>Array</code>, <code>Hash</code>, <code>File</code>, <code>Range</code>, etc) will return a lazy enumerator, that doesn&#8217;t perform any calculations till it is forced to. In addition, elements of the enumerable will be sent though the whole chain one by one, rather than evaluating the entire enumerable at each step. In some cases this will result in less work.</p>

<p>You can deal with infinite collections</p>
<div class='highlight'><pre><code class='ruby'><span class='o'>[</span><span class='mi'>1</span><span class='p'>,</span><span class='mi'>2</span><span class='p'>,</span><span class='mi'>3</span><span class='o'>].</span><span class='n'>lazy</span><span class='o'>.</span><span class='n'>cycle</span><span class='o'>.</span><span class='n'>map</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>x</span><span class='o'>|</span> <span class='n'>x</span> <span class='o'>*</span> <span class='mi'>10</span><span class='p'>}</span><span class='o'>.</span><span class='n'>take</span><span class='p'>(</span><span class='mi'>5</span><span class='p'>)</span><span class='o'>.</span><span class='n'>to_a</span>   <span class='c1'>#=&gt; [10, 20, 30, 10, 20]</span>
</code></pre></div>
<p>Or avoid consuming large resources, when you know you&#8217;ll only need a little</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>File</span><span class='o'>.</span><span class='n'>open</span><span class='p'>(</span><span class='bp'>__FILE__</span><span class='p'>)</span><span class='o'>.</span><span class='n'>lazy</span><span class='o'>.</span><span class='n'>each</span><span class='o'>.</span><span class='n'>map</span><span class='p'>(</span><span class='o'>&amp;</span><span class='ss'>:chomp</span><span class='p'>)</span><span class='o'>.</span><span class='n'>reject</span><span class='p'>(</span><span class='o'>&amp;</span><span class='ss'>:empty?</span><span class='p'>)</span><span class='o'>.</span><span class='n'>take</span><span class='p'>(</span><span class='mi'>3</span><span class='p'>)</span><span class='o'>.</span><span class='n'>force</span>
</code></pre></div>
<p>This example only reads as many lines as it takes to find 3 that aren&#8217;t empty.</p>

<p><code>#lazy</code> does incur a performance penalty, so you&#8217;ll need to make sure you&#8217;re only using it when it makes sense.</p>

<p>There&#8217;s also a <code>Enumerator::Lazy</code> class to create your own lazy enumerators. The example above could be written as:</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>populated_lines</span><span class='p'>(</span><span class='n'>file</span><span class='p'>,</span> <span class='o'>&amp;</span><span class='n'>block</span><span class='p'>)</span>
  <span class='ss'>Enumerator</span><span class='p'>:</span><span class='ss'>:Lazy</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='n'>file</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>yielder</span><span class='p'>,</span> <span class='n'>line</span><span class='o'>|</span>
    <span class='n'>string</span> <span class='o'>=</span> <span class='n'>line</span><span class='o'>.</span><span class='n'>chomp</span>
    <span class='n'>yielder</span> <span class='o'>&lt;&lt;</span> <span class='n'>string</span> <span class='k'>unless</span> <span class='n'>string</span><span class='o'>.</span><span class='n'>empty?</span>
  <span class='k'>end</span><span class='o'>.</span><span class='n'>each</span><span class='p'>(</span><span class='o'>&amp;</span><span class='n'>block</span><span class='p'>)</span> <span class='c1'># evals block, or returns enum if nil, like stdlib</span>
<span class='k'>end</span>

<span class='n'>populated_lines</span><span class='p'>(</span><span class='no'>File</span><span class='o'>.</span><span class='n'>open</span><span class='p'>(</span><span class='bp'>__FILE__</span><span class='p'>))</span><span class='o'>.</span><span class='n'>take</span><span class='p'>(</span><span class='mi'>3</span><span class='p'>)</span><span class='o'>.</span><span class='n'>force</span>
</code></pre></div>
<h2 id='lazy__and_'>Lazy <code>Enumerator#size</code> and <code>Range#size</code></h2>

<p><code>Enumerator#size</code> will return the size of an enumerator, without evaluating the whole <code>Enumerator.</code> Range benefits from this too.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>array</span> <span class='o'>=</span> <span class='o'>[</span><span class='mi'>1</span><span class='p'>,</span><span class='mi'>2</span><span class='p'>,</span><span class='mi'>3</span><span class='p'>,</span><span class='mi'>4</span><span class='o'>]</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>cycle</span><span class='p'>(</span><span class='mi'>4</span><span class='p'>)</span><span class='o'>.</span><span class='n'>size</span>    <span class='c1'>#=&gt; 16</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>cycle</span><span class='o'>.</span><span class='n'>size</span>       <span class='c1'>#=&gt; Infinity</span>
<span class='c1'># nil is returned if the size can&#39;t be calculated</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>find</span><span class='o'>.</span><span class='n'>size</span>        <span class='c1'>#=&gt; nil</span>
<span class='c1'># Range too</span>
<span class='p'>(</span><span class='mi'>1</span><span class='o'>.</span><span class='n'>.</span><span class='mi'>10</span><span class='p'>)</span><span class='o'>.</span><span class='n'>size</span>           <span class='c1'>#=&gt; 10</span>
</code></pre></div>
<p>To enable this in <code>Enumerators</code> returned from your own code, <code>Enumerator.new</code> now accepts an argument to calculate the size.</p>

<p>This can be a value</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>enum</span> <span class='o'>=</span> <span class='no'>Enumerator</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='mi'>3</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>yielder</span><span class='o'>|</span>
  <span class='n'>yielder</span> <span class='o'>&lt;&lt;</span> <span class='s2'>&quot;a&quot;</span>
  <span class='n'>yielder</span> <span class='o'>&lt;&lt;</span> <span class='s2'>&quot;b&quot;</span>
  <span class='n'>yielder</span> <span class='o'>&lt;&lt;</span> <span class='s2'>&quot;c&quot;</span>
<span class='k'>end</span>

<span class='n'>enum</span><span class='o'>.</span><span class='n'>size</span>              <span class='c1'>#=&gt; 3</span>
</code></pre></div>
<p>or an object responding to <code>#call</code></p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>square_times</span><span class='p'>(</span><span class='n'>num</span><span class='p'>,</span> <span class='o'>&amp;</span><span class='n'>block</span><span class='p'>)</span>
  <span class='no'>Enumerator</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='o'>-&gt;</span> <span class='p'>{</span><span class='n'>num</span> <span class='o'>**</span> <span class='mi'>2</span><span class='p'>})</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>yielder</span><span class='o'>|</span>
    <span class='p'>(</span><span class='n'>num</span> <span class='o'>**</span> <span class='mi'>2</span><span class='p'>)</span><span class='o'>.</span><span class='n'>times</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>i</span><span class='o'>|</span> <span class='n'>yielder</span> <span class='o'>&lt;&lt;</span> <span class='n'>i</span><span class='p'>}</span>
  <span class='k'>end</span><span class='o'>.</span><span class='n'>each</span><span class='p'>(</span><span class='o'>&amp;</span><span class='n'>block</span><span class='p'>)</span>
<span class='k'>end</span>

<span class='n'>square_times</span><span class='p'>(</span><span class='mi'>6</span><span class='p'>)</span><span class='o'>.</span><span class='n'>size</span>     <span class='c1'>#=&gt; 36</span>
</code></pre></div>
<p><code>#to_enum</code> (and it&#8217;s alias <code>#enum_for)</code> also now take a block to calculate the size, so the above could be written like so:</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>square_times</span><span class='p'>(</span><span class='n'>num</span><span class='p'>)</span>
  <span class='k'>return</span> <span class='n'>to_enum</span><span class='p'>(</span><span class='ss'>:square_times</span><span class='p'>)</span> <span class='p'>{</span><span class='n'>num</span> <span class='o'>**</span> <span class='mi'>2</span><span class='p'>}</span> <span class='k'>unless</span> <span class='nb'>block_given?</span>
  <span class='p'>(</span><span class='n'>num</span> <span class='o'>**</span> <span class='mi'>2</span><span class='p'>)</span><span class='o'>.</span><span class='n'>times</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>i</span><span class='o'>|</span>
    <span class='k'>yield</span> <span class='n'>i</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='n'>square_times</span><span class='p'>(</span><span class='mi'>6</span><span class='p'>)</span><span class='o'>.</span><span class='n'>size</span>     <span class='c1'>#=&gt; 36</span>
</code></pre></div>
<h2 id='rubygems_gemfile_support'>Rubygems Gemfile support</h2>

<p>Rubygems can now use your Gemfile (or Isolate, or gem.deps.rb) to install gems and load activation information.</p>

<p>You can install the gems listed in your Gemfile (and their dependancies) by specifying the <code>--file</code> (or <code>-g</code>) option. This only uses the Gemfile, not Gemfile.lock, so only versions specified in the Gemfile will be respected.</p>
<div class='highlight'><pre><code class='bash'>gem install --file Gemfile
</code></pre></div>
<p>To load activation information (the version of the gems to use) specify the <code>RUBYGEMS_GEMDEPS</code> environment variable. The value for this should be the path to your Gemfile, but you can use <code>-</code> to have Rubygems auto-detect this.</p>

<p>Like install, this only uses the Gemfile, ignoring Gemfile.lock, so it&#8217;s less strict than Bundler. It also only activates the specified versions, you&#8217;ll still need to require the gems in your code.</p>

<p>It does have the advantage that as it&#8217;s built in, there&#8217;s no need for something similar to <code>bundle exec</code> or Bundlers binstubs, just run your app like normal.</p>
<div class='highlight'><pre><code class='bash'><span class='nb'>export </span><span class='nv'>RUBYGEMS_GEMDEPS</span><span class='o'>=</span>-
<span class='c'># start your app</span>
</code></pre></div>
<p>There is only basic support for the Gemfile format, it doesn&#8217;t understand the <code>gemspec</code> declaration for example, but it&#8217;s a handy feature that will hopefully evolve and become a bit more robust, and it&#8217;s very useful if Bundler isn&#8217;t working out for you.</p>

<p>A rough approximation of <code>bundle install --path vendor/bundle</code> can be had with</p>
<div class='highlight'><pre><code class='bash'>gem install --file Gemfile --install-dir vendor/gem

<span class='nb'>export </span><span class='nv'>GEM_HOME</span><span class='o'>=</span>vendor/gem
<span class='nb'>export </span><span class='nv'>RUBYGEMS_GEMDEPS</span><span class='o'>=</span>-
<span class='c'># start your app</span>
</code></pre></div>
<h2 id='rdoc_markdown_support'>RDoc markdown support</h2>

<p>RDoc now understands markdown, to run rdoc with markdown formatting set the markup option</p>
<div class='highlight'><pre><code class='bash'>rdoc --markup markdown
</code></pre></div>
<p>This can be saved in your project with a .doc_options file so you don&#8217;t need to repeat it every time</p>
<div class='highlight'><pre><code class='bash'>rdoc --markup markdown --write-options
</code></pre></div>
<h2 id='use_warn_like_puts'>Use warn like puts</h2>

<p>warn now works just like puts, taking multiple arguments, or an array, and outputting them, but on stderr rather than stdout</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>warn</span> <span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='s2'>&quot;bar&quot;</span>
<span class='nb'>warn</span> <span class='o'>[</span><span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='s2'>&quot;bar&quot;</span><span class='o'>]</span>
</code></pre></div>
<h2 id='logger_compatible_syslog_interface'>Logger compatible syslog interface</h2>

<p>Now it&#8217;s super easy to switch between logging to a file descriptor and to syslog, no more picking one and then writing to that interface. You can even log to stdout in development, and syslog in production, without having to update all your logging calls.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>if</span> <span class='no'>ENV</span><span class='o'>[</span><span class='s2'>&quot;RACK_ENV&quot;</span><span class='o'>]</span> <span class='o'>==</span> <span class='s2'>&quot;production&quot;</span>
  <span class='nb'>require</span> <span class='s2'>&quot;syslog&quot;</span>
  <span class='n'>logger</span> <span class='o'>=</span> <span class='ss'>Syslog</span><span class='p'>:</span><span class='ss'>:Logger</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='s2'>&quot;my_app&quot;</span><span class='p'>)</span>
<span class='k'>else</span>
  <span class='nb'>require</span> <span class='s2'>&quot;logger&quot;</span>
  <span class='n'>logger</span> <span class='o'>=</span> <span class='no'>Logger</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='no'>STDOUT</span><span class='p'>)</span>
<span class='k'>end</span>

<span class='n'>logger</span><span class='o'>.</span><span class='n'>debug</span><span class='p'>(</span><span class='s2'>&quot;about to do stuff&quot;</span><span class='p'>)</span>
<span class='k'>begin</span>
  <span class='n'>do_stuff</span>
<span class='k'>rescue</span> <span class='o'>=&gt;</span> <span class='n'>e</span>
  <span class='n'>logger</span><span class='o'>.</span><span class='n'>error</span><span class='p'>(</span><span class='n'>e</span><span class='o'>.</span><span class='n'>message</span><span class='p'>)</span>
<span class='k'>end</span>
<span class='n'>logger</span><span class='o'>.</span><span class='n'>info</span><span class='p'>(</span><span class='s2'>&quot;stuff done&quot;</span><span class='p'>)</span>
</code></pre></div>
<h2 id='tracepoint'>TracePoint</h2>

<p><code>TracePoint</code> is a new object oriented version of the old <code>Kernel#set_trace_func</code>. It allows you to trace the execution of your Ruby code, this can be really handy when debugging code that isn&#8217;t terribly straight forward.</p>
<div class='highlight'><pre><code class='ruby'><span class='c1'># set up our tracer, but don&#39;t enable it yet</span>
<span class='n'>events</span> <span class='o'>=</span> <span class='o'>%</span><span class='n'>i</span><span class='p'>{</span><span class='n'>call</span> <span class='k'>return</span> <span class='n'>b_call</span> <span class='n'>b_return</span> <span class='k'>raise</span><span class='p'>}</span>
<span class='n'>trace</span> <span class='o'>=</span> <span class='no'>TracePoint</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='o'>*</span><span class='n'>events</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>tp</span><span class='o'>|</span>
  <span class='nb'>p</span> <span class='o'>[</span><span class='n'>tp</span><span class='o'>.</span><span class='n'>event</span><span class='p'>,</span> <span class='n'>tp</span><span class='o'>.</span><span class='n'>event</span> <span class='o'>==</span> <span class='ss'>:raise</span> <span class='p'>?</span> <span class='n'>tp</span><span class='o'>.</span><span class='n'>raised_exception</span><span class='o'>.</span><span class='n'>class</span> <span class='p'>:</span> <span class='n'>tp</span><span class='o'>.</span><span class='n'>method_id</span><span class='p'>,</span> <span class='n'>tp</span><span class='o'>.</span><span class='n'>path</span><span class='p'>,</span> <span class='n'>tp</span><span class='o'>.</span><span class='n'>lineno</span><span class='o'>]</span>
<span class='k'>end</span>

<span class='k'>def</span> <span class='nf'>twice</span>
  <span class='n'>result</span> <span class='o'>=</span> <span class='o'>[]</span>
  <span class='n'>result</span> <span class='o'>&lt;&lt;</span> <span class='k'>yield</span>
  <span class='n'>result</span> <span class='o'>&lt;&lt;</span> <span class='k'>yield</span>
  <span class='n'>result</span>
<span class='k'>end</span>

<span class='k'>def</span> <span class='nf'>check_idempotence</span><span class='p'>(</span><span class='o'>&amp;</span><span class='n'>block</span><span class='p'>)</span>
  <span class='n'>a</span><span class='p'>,</span> <span class='n'>b</span> <span class='o'>=</span> <span class='n'>twice</span><span class='p'>(</span><span class='o'>&amp;</span><span class='n'>block</span><span class='p'>)</span>
  <span class='k'>raise</span> <span class='s2'>&quot;expected </span><span class='si'>#{</span><span class='n'>a</span><span class='si'>}</span><span class='s2'> to equal </span><span class='si'>#{</span><span class='n'>b</span><span class='si'>}</span><span class='s2'>&quot;</span> <span class='k'>unless</span> <span class='n'>a</span> <span class='o'>==</span> <span class='n'>b</span>
  <span class='kp'>true</span>
<span class='k'>end</span>

<span class='n'>trace</span><span class='o'>.</span><span class='n'>enable</span>
<span class='n'>a</span> <span class='o'>=</span> <span class='mi'>1</span>
<span class='k'>begin</span>
  <span class='n'>check_idempotence</span> <span class='p'>{</span><span class='n'>a</span> <span class='o'>+=</span> <span class='mi'>1</span><span class='p'>}</span>
<span class='k'>rescue</span>
<span class='k'>end</span>
<span class='n'>trace</span><span class='o'>.</span><span class='n'>disable</span>
</code></pre></div>
<p>outputs:</p>
<div class='highlight'><pre><code class='ruby'><span class='o'>[</span><span class='ss'>:call</span><span class='p'>,</span> <span class='ss'>:check_idempotence</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>841</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:call</span><span class='p'>,</span> <span class='ss'>:twice</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>834</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:b_call</span><span class='p'>,</span> <span class='kp'>nil</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>850</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:b_return</span><span class='p'>,</span> <span class='kp'>nil</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>850</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:b_call</span><span class='p'>,</span> <span class='kp'>nil</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>850</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:b_return</span><span class='p'>,</span> <span class='kp'>nil</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>850</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:return</span><span class='p'>,</span> <span class='ss'>:twice</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>839</span><span class='o'>]</span>
<span class='o'>[</span><span class='ss'>:raise</span><span class='p'>,</span> <span class='c1'>#&lt;RuntimeError: expected 2 to equal 3&gt;, &quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;, 843]</span>
<span class='o'>[</span><span class='ss'>:return</span><span class='p'>,</span> <span class='ss'>:check_idempotence</span><span class='p'>,</span> <span class='s2'>&quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span><span class='p'>,</span> <span class='mi'>843</span><span class='o'>]</span>
</code></pre></div>
<h2 id='asynchronous_thread_interrupt_handling'>Asynchronous Thread interrupt handling</h2>

<p>Ruby threads can be killed or have an exception raised in them by another. This isn&#8217;t a terribly safe feature as the killing thread doesn&#8217;t know what the thread being killed is doing, you could end up killing a thread in the middle of some important resource allocation or deallocation. We now have a feature to deal with this more safely.</p>

<p>As an example, the stdlib timeout library works by spawning a second thread, which waits for the specified amount of time, and then raises and exception in the original thread.</p>

<p>Say we had a connection pool library that could cope fine with you failing to check back in a connection, but would fail if checking out or checking in a connection was interrupted. You&#8217;re writing a method to get a connection, make a request on it, then return it, and you suspect that users of this method may wrap it in a timeout.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>request</span><span class='p'>(</span><span class='n'>details</span><span class='p'>)</span>
  <span class='n'>result</span> <span class='o'>=</span> <span class='kp'>nil</span>
  <span class='c1'># Block will defer given exceptions if they are raised in this thread by</span>
  <span class='c1'># another thread till the end of the block. Exceptions are not rescured or</span>
  <span class='c1'># ignored, but handled later.</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>handle_interrupt</span><span class='p'>(</span><span class='ss'>Timeout</span><span class='p'>:</span><span class='ss'>:ExitException</span> <span class='o'>=&gt;</span> <span class='ss'>:never</span><span class='p'>)</span> <span class='k'>do</span>
    <span class='c1'># no danger of timeout interrupting checkout</span>
    <span class='n'>connection</span> <span class='o'>=</span> <span class='n'>connection_pool</span><span class='o'>.</span><span class='n'>checkout</span>
    <span class='c1'># if checkout took too long, handle the interrupt immediately, effectively</span>
    <span class='c1'># raising the pending exception here</span>
    <span class='k'>if</span> <span class='no'>Thread</span><span class='o'>.</span><span class='n'>pending_interrupt?</span>
      <span class='no'>Thread</span><span class='o'>.</span><span class='n'>handle_interrupt</span><span class='p'>(</span><span class='ss'>Timeout</span><span class='p'>:</span><span class='ss'>:ExitException</span> <span class='o'>=&gt;</span> <span class='ss'>:immediate</span><span class='p'>)</span>
    <span class='k'>end</span>
    <span class='c1'># allow interrupts during IO (or C extension call)</span>
    <span class='no'>Thread</span><span class='o'>.</span><span class='n'>handle_interrupt</span><span class='p'>(</span><span class='ss'>Timeout</span><span class='p'>:</span><span class='ss'>:ExitException</span> <span class='o'>=&gt;</span> <span class='ss'>:on_blocking</span><span class='p'>)</span> <span class='k'>do</span>
      <span class='n'>result</span> <span class='o'>=</span> <span class='n'>connection</span><span class='o'>.</span><span class='n'>request</span><span class='p'>(</span><span class='n'>details</span><span class='p'>)</span>
    <span class='k'>end</span>
    <span class='c1'># no danger of timeout interrupting checkin</span>
    <span class='n'>connection_pool</span><span class='o'>.</span><span class='n'>checkin</span><span class='p'>(</span><span class='n'>connection</span><span class='p'>)</span>
  <span class='k'>end</span>
<span class='k'>end</span>
</code></pre></div>
<p>This method can safely be wrapped in a timeout, and the connection will always be completely checked out, and if it completes the request, will always be completes checked in. If the timeout happens during checkin, it won&#8217;t interrupt the checkin, but it will still be raised at the end of the method.</p>

<p>This is a slightly contrived example, but it covers the main points of this great new feature.</p>

<h2 id='garbage_collection_improvements'>Garbage collection improvements</h2>

<p>There are a few improvements to the garbage collector in Ruby 2.0, the main one making Ruby play nicer with Copy-on-Write. This means applications that fork multiple processes, like a Rails app running on Unicorn, will use less memory.</p>

<p>The GC::Profiler class also gets a ::raw_data method, to return the raw data of the profile as an array of hashes, rather than a string, making it easier to log this data with say, statsd.</p>
<div class='highlight'><pre><code class='ruby'><span class='ss'>GC</span><span class='p'>:</span><span class='ss'>:Profiler</span><span class='o'>.</span><span class='n'>enable</span> <span class='c1'># turn on the profiler</span>
<span class='no'>GC</span><span class='o'>.</span><span class='n'>start</span> <span class='c1'># force a GC run, so there will be some stats</span>
<span class='ss'>GC</span><span class='p'>:</span><span class='ss'>:Profiler</span><span class='o'>.</span><span class='n'>raw_data</span>
<span class='c1'>#=&gt; [{:GC_TIME=&gt;0.0012150000000000008, :GC_INVOKE_TIME=&gt;0.036716,</span>
<span class='c1'>#   :HEAP_USE_SIZE=&gt;435920, :HEAP_TOTAL_SIZE=&gt;700040,</span>
<span class='c1'>#   :HEAP_TOTAL_OBJECTS=&gt;17501, :GC_IS_MARKED=&gt;0}]</span>
</code></pre></div>
<h2 id='id6'><code>ObjectSpace.reachable_objects_from</code></h2>

<p>This method returns all the objects directly reachable from the given object.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;objspace&quot;</span>

<span class='no'>Response</span> <span class='o'>=</span> <span class='no'>Struct</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='ss'>:code</span><span class='p'>,</span> <span class='ss'>:header</span><span class='p'>,</span> <span class='ss'>:body</span><span class='p'>)</span>
<span class='n'>res</span> <span class='o'>=</span> <span class='no'>Response</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='mi'>200</span><span class='p'>,</span> <span class='p'>{</span><span class='s2'>&quot;Content-Length&quot;</span> <span class='o'>=&gt;</span> <span class='s2'>&quot;12&quot;</span><span class='p'>},</span> <span class='s2'>&quot;Hello world!&quot;</span><span class='p'>)</span>

<span class='no'>ObjectSpace</span><span class='o'>.</span><span class='n'>reachable_objects_from</span><span class='p'>(</span><span class='n'>res</span><span class='p'>)</span>
<span class='c1'>#=&gt; [Response, {&quot;Content-Length&quot;=&gt;&quot;12&quot;}, &quot;Hello world!&quot;]</span>
</code></pre></div>
<p>You can combine this with <code>ObjectSpace.memsize_of</code> to get an idea of the memory size of an object and all the objects it references; very handy for debugging memory leaks</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>memsize_of_all_reachable_objects_from</span><span class='p'>(</span><span class='n'>obj</span><span class='p'>)</span>
  <span class='n'>memsize</span> <span class='o'>=</span> <span class='mi'>0</span>
  <span class='n'>seen</span> <span class='o'>=</span> <span class='p'>{}</span><span class='o'>.</span><span class='n'>tap</span><span class='p'>(</span><span class='o'>&amp;</span><span class='ss'>:compare_by_identity</span><span class='p'>)</span>
  <span class='n'>to_do</span> <span class='o'>=</span> <span class='o'>[</span><span class='n'>obj</span><span class='o'>]</span>
  <span class='k'>while</span> <span class='n'>obj</span> <span class='o'>=</span> <span class='n'>to_do</span><span class='o'>.</span><span class='n'>shift</span>
    <span class='no'>ObjectSpace</span><span class='o'>.</span><span class='n'>reachable_objects_from</span><span class='p'>(</span><span class='n'>obj</span><span class='p'>)</span><span class='o'>.</span><span class='n'>each</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>o</span><span class='o'>|</span>
      <span class='k'>next</span> <span class='k'>if</span> <span class='n'>seen</span><span class='o'>.</span><span class='n'>key?</span><span class='p'>(</span><span class='n'>o</span><span class='p'>)</span> <span class='o'>||</span> <span class='no'>Module</span> <span class='o'>===</span> <span class='n'>o</span>
      <span class='n'>seen</span><span class='o'>[</span><span class='n'>o</span><span class='o'>]</span> <span class='o'>=</span> <span class='kp'>true</span>
      <span class='n'>memsize</span> <span class='o'>+=</span> <span class='no'>ObjectSpace</span><span class='o'>.</span><span class='n'>memsize_of</span><span class='p'>(</span><span class='n'>o</span><span class='p'>)</span>
      <span class='n'>to_do</span> <span class='o'>&lt;&lt;</span> <span class='n'>o</span>
    <span class='k'>end</span>
  <span class='k'>end</span>
  <span class='n'>memsize</span>
<span class='k'>end</span>

<span class='n'>memsize_of_all_reachable_objects_from</span><span class='p'>(</span><span class='n'>res</span><span class='p'>)</span>   <span class='c1'>#=&gt; 192</span>
</code></pre></div>
<h2 id='optimised_backtrace'>Optimised backtrace</h2>

<p>Backtrace strings are now only created on demand, from a light weight collection of object, rather than with each exception. You can get ahold of these objects with <code>caller_locations</code> or <code>Thread#backtrace_locations.</code> Curiously they aren&#8217;t available from an <code>Exception</code>.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>foo</span>
  <span class='n'>bar</span>
<span class='k'>end</span>

<span class='k'>def</span> <span class='nf'>bar</span>
  <span class='n'>caller_locations</span>
<span class='k'>end</span>

<span class='n'>locations</span> <span class='o'>=</span> <span class='n'>foo</span>
<span class='n'>locations</span><span class='o'>.</span><span class='n'>map</span><span class='p'>(</span><span class='o'>&amp;</span><span class='ss'>:label</span><span class='p'>)</span>   <span class='c1'>#=&gt; [&quot;foo&quot;, &quot;&lt;main&gt;&quot;]</span>
<span class='n'>locations</span><span class='o'>.</span><span class='n'>first</span><span class='o'>.</span><span class='n'>class</span>    <span class='c1'>#=&gt; Thread::Backtrace::Location</span>
</code></pre></div>
<p><code>caller</code> also now accepts a limit as well as an offset, or a range</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>bar</span>
  <span class='nb'>caller</span><span class='p'>(</span><span class='mi'>2</span><span class='p'>,</span> <span class='mi'>1</span><span class='p'>)</span>
<span class='k'>end</span>
<span class='n'>foo</span>   <span class='c1'>#=&gt; [&quot;/Users/mat/Dropbox/ruby-2.0.0.rb:361:in `&lt;main&gt;&#39;&quot;]</span>

<span class='k'>def</span> <span class='nf'>bar</span>
  <span class='nb'>caller</span><span class='p'>(</span><span class='mi'>2</span><span class='o'>.</span><span class='n'>.</span><span class='mi'>2</span><span class='p'>)</span>
<span class='k'>end</span>
<span class='n'>foo</span>   <span class='c1'>#=&gt; [&quot;/Users/mat/Dropbox/ruby-2.0.0.rb:368:in `&lt;main&gt;&#39;&quot;]</span>
</code></pre></div>
<h2 id='zlib_streaming_support'>Zlib streaming support</h2>

<p>Zlib gets support for streaming decompression and improved support for streaming compression.</p>

<p>When decompressing files it might be reasonable to buffer the whole compressed file in to memory, but the uncompressed data may be many hundreds of MB. <code>Zlib::Inflate#inflate</code> now accepts a block that will get chunks of data as the file in uncompressed, this can process the uncompressed data without needing to buffer all of it in memory at once.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;zlib&quot;</span>

<span class='n'>inflater</span> <span class='o'>=</span> <span class='ss'>Zlib</span><span class='p'>:</span><span class='ss'>:Inflate</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='ss'>Zlib</span><span class='p'>:</span><span class='ss'>:MAX_WBITS</span> <span class='o'>+</span> <span class='mi'>32</span><span class='p'>)</span>
<span class='no'>File</span><span class='o'>.</span><span class='n'>open</span><span class='p'>(</span><span class='s2'>&quot;app.log&quot;</span><span class='p'>,</span> <span class='s2'>&quot;w&quot;</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>out</span><span class='o'>|</span>
  <span class='n'>inflater</span><span class='o'>.</span><span class='n'>inflate</span><span class='p'>(</span><span class='no'>File</span><span class='o'>.</span><span class='n'>read</span><span class='p'>(</span><span class='s2'>&quot;app.log.gz&quot;</span><span class='p'>))</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>chunk</span><span class='o'>|</span> <span class='n'>out</span> <span class='o'>&lt;&lt;</span> <span class='n'>chunk</span><span class='p'>}</span>
<span class='k'>end</span>
<span class='n'>inflater</span><span class='o'>.</span><span class='n'>close</span>
</code></pre></div>
<p>In a similar fashion <code>Zlib::Deflate#deflate</code> also accepts a block, as you feed data in to <code>#deflate</code> the block will only be called when enough data has accumulated to warrant efficient compression.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>deflater</span> <span class='o'>=</span> <span class='ss'>Zlib</span><span class='p'>:</span><span class='ss'>:Deflate</span><span class='o'>.</span><span class='n'>new</span>
<span class='no'>File</span><span class='o'>.</span><span class='n'>open</span><span class='p'>(</span><span class='s2'>&quot;app.log.gz&quot;</span><span class='p'>,</span> <span class='s2'>&quot;w&quot;</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>out</span><span class='o'>|</span>
  <span class='no'>File</span><span class='o'>.</span><span class='n'>foreach</span><span class='p'>(</span><span class='s2'>&quot;app.log&quot;</span><span class='p'>,</span> <span class='mi'>4</span> <span class='o'>*</span> <span class='mi'>1024</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>chunk</span><span class='o'>|</span>
    <span class='n'>deflater</span><span class='o'>.</span><span class='n'>deflate</span><span class='p'>(</span><span class='n'>chunk</span><span class='p'>)</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>part</span><span class='o'>|</span> <span class='n'>out</span> <span class='o'>&lt;&lt;</span> <span class='n'>part</span><span class='p'>}</span>
  <span class='k'>end</span>
  <span class='n'>deflater</span><span class='o'>.</span><span class='n'>finish</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>part</span><span class='o'>|</span> <span class='n'>out</span> <span class='o'>&lt;&lt;</span> <span class='n'>part</span><span class='p'>}</span>
<span class='k'>end</span>
</code></pre></div>
<h2 id='multithreaded_zlib_processing'>Multithreaded Zlib processing</h2>

<p>Zlib no longer holds the Global Interpreter Lock while compressing/uncompressing data, allowing parallel processing on gzip, zlib and deflate streams. This also means your application can continue to respond while Zlib works in the background.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;zlib&quot;</span>

<span class='c1'># processes 4 files in parallel, using 4 cores if required</span>
<span class='n'>threads</span> <span class='o'>=</span> <span class='sx'>%W{a.txt.gz b.txt.gz c.txt.gz d.txt.gz}</span><span class='o'>.</span><span class='n'>map</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>path</span><span class='o'>|</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
    <span class='n'>inflater</span> <span class='o'>=</span> <span class='ss'>Zlib</span><span class='p'>:</span><span class='ss'>:Inflate</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='ss'>Zlib</span><span class='p'>:</span><span class='ss'>:MAX_WBITS</span> <span class='o'>+</span> <span class='mi'>32</span><span class='p'>)</span>
    <span class='no'>File</span><span class='o'>.</span><span class='n'>open</span><span class='p'>(</span><span class='n'>path</span><span class='o'>.</span><span class='n'>chomp</span><span class='p'>(</span><span class='no'>File</span><span class='o'>.</span><span class='n'>extname</span><span class='p'>(</span><span class='n'>path</span><span class='p'>)),</span> <span class='s2'>&quot;w&quot;</span><span class='p'>)</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>out</span><span class='o'>|</span>
      <span class='n'>inflater</span><span class='o'>.</span><span class='n'>inflate</span><span class='p'>(</span><span class='no'>File</span><span class='o'>.</span><span class='n'>read</span><span class='p'>(</span><span class='n'>path</span><span class='p'>))</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>chunk</span><span class='o'>|</span> <span class='n'>out</span> <span class='o'>&lt;&lt;</span> <span class='n'>chunk</span><span class='p'>}</span>
    <span class='k'>end</span>
    <span class='n'>inflater</span><span class='o'>.</span><span class='n'>close</span>
  <span class='k'>end</span>
<span class='k'>end</span>
<span class='c1'># do other stuff here while Zlib works in other threads</span>
<span class='n'>threads</span><span class='o'>.</span><span class='n'>map</span><span class='p'>(</span><span class='o'>&amp;</span><span class='ss'>:join</span><span class='p'>)</span>
</code></pre></div>
<h2 id='default_utf8_encoding'>Default UTF-8 encoding</h2>

<p>You can now use useful characters outside of US-ASCII without magic encoding comments or inscrutable escape sequences</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>currency</span> <span class='o'>=</span> <span class='s2'>&quot;€&quot;</span>   <span class='c1'>#=&gt; &quot;€&quot;</span>
</code></pre></div>
<h2 id='binary_string_shortcut'>Binary string shortcut</h2>

<p><code>String#b</code> as a shortcut to get an ASCII-8BIT (aka binary) copy of a string</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>s</span> <span class='o'>=</span> <span class='s2'>&quot;foo&quot;</span>
<span class='n'>s</span><span class='o'>.</span><span class='n'>encoding</span>     <span class='c1'>#=&gt; #&lt;Encoding:UTF-8&gt;</span>
<span class='n'>s</span><span class='o'>.</span><span class='n'>b</span><span class='o'>.</span><span class='n'>encoding</span>   <span class='c1'>#=&gt; #&lt;Encoding:ASCII-8BIT&gt;</span>
</code></pre></div>
<h2 id='__etc_return_an_'><code>String#lines</code>, <code>#chars</code>, etc return an <code>Array</code></h2>

<p>lines, chars, codepoints, bytes now all return arrays rather then enumerators</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>s</span> <span class='o'>=</span> <span class='s2'>&quot;foo</span><span class='se'>\n</span><span class='s2'>bar&quot;</span>
<span class='n'>s</span><span class='o'>.</span><span class='n'>lines</span>        <span class='c1'>#=&gt; [&quot;foo\n&quot;, &quot;bar&quot;]</span>
<span class='n'>s</span><span class='o'>.</span><span class='n'>chars</span>        <span class='c1'>#=&gt; [&quot;f&quot;, &quot;o&quot;, &quot;o&quot;, &quot;\n&quot;, &quot;b&quot;, &quot;a&quot;, &quot;r&quot;]</span>
<span class='n'>s</span><span class='o'>.</span><span class='n'>codepoints</span>   <span class='c1'>#=&gt; [102, 111, 111, 10, 98, 97, 114]</span>
<span class='n'>s</span><span class='o'>.</span><span class='n'>bytes</span>        <span class='c1'>#=&gt; [102, 111, 111, 10, 98, 97, 114]</span>
</code></pre></div>
<p>These still accept a block for backwards compatibility, but you should use <code>#each_line</code> etc for that use case</p>

<p>The similarly named methods on IO, ARGF, StringIO, and Zlib::GzipReader still return enumerators, but are deprecated, use the <code>each_*</code> versions.</p>

<h2 id='id7'><code>__dir__</code></h2>

<p>Returns the file path to the executing file, like <code>__FILE__</code>, but without the file name, useful for things like</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>YAML</span><span class='o'>.</span><span class='n'>load_file</span><span class='p'>(</span><span class='no'>File</span><span class='o'>.</span><span class='n'>join</span><span class='p'>(</span><span class='n'>__dir__</span><span class='p'>,</span> <span class='s2'>&quot;config.yml&quot;</span><span class='p'>))</span>
</code></pre></div>
<h2 id='_returns_the_method_as_called'><code>__callee__</code> returns the method as called</h2>

<p><code>__callee__</code> is back to returning the name of the method as called, not as defined with an aliased method. This can actually be useful.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>do_request</span><span class='p'>(</span><span class='nb'>method</span><span class='p'>,</span> <span class='n'>path</span><span class='p'>,</span> <span class='n'>headers</span><span class='o'>=</span><span class='p'>{},</span> <span class='n'>body</span><span class='o'>=</span><span class='kp'>nil</span><span class='p'>)</span>
  <span class='s2'>&quot;</span><span class='si'>#{</span><span class='nb'>method</span><span class='o'>.</span><span class='n'>upcase</span><span class='si'>}</span><span class='s2'> </span><span class='si'>#{</span><span class='n'>path</span><span class='si'>}</span><span class='s2'>&quot;</span>
<span class='k'>end</span>

<span class='k'>def</span> <span class='nf'>get</span><span class='p'>(</span><span class='n'>path</span><span class='p'>,</span> <span class='n'>headers</span><span class='o'>=</span><span class='p'>{})</span>
  <span class='n'>do_request</span><span class='p'>(</span><span class='n'>__callee__</span><span class='p'>,</span> <span class='n'>path</span><span class='p'>,</span> <span class='n'>headers</span><span class='p'>)</span>
<span class='k'>end</span>
<span class='k'>alias</span> <span class='n'>head</span> <span class='n'>get</span>

<span class='n'>get</span><span class='p'>(</span><span class='s2'>&quot;/test&quot;</span><span class='p'>)</span>    <span class='c1'>#=&gt; &quot;GET /test&quot;</span>
<span class='n'>head</span><span class='p'>(</span><span class='s2'>&quot;/test&quot;</span><span class='p'>)</span>   <span class='c1'>#=&gt; &quot;HEAD /test&quot;</span>
</code></pre></div>
<h2 id='regexp_engine_is_changed_to_onigmo'>RegExp engine is changed to Onigmo</h2>

<p>Onigmo is a fork of the Oniguruma regexp engine used by 1.9, with a few more <a href='https://github.com/k-takata/Onigmo'>features</a>. The new features seem Perl-inspired, <a href='http://perldoc.perl.org/perlre.html'>this</a> seems to be a good refrence.</p>
<div class='highlight'><pre><code class='ruby'><span class='p'>(?(</span><span class='n'>cond</span><span class='p'>)</span><span class='n'>yes</span><span class='o'>|</span><span class='n'>no</span><span class='p'>)</span>
</code></pre></div>
<p>if cond is matched, then match against yes, if cond is false match against no cond references a match either by group number or name, or is a look-ahead/behind</p>

<p>example only matches a trailing cap if there is a leading cap</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>regexp</span> <span class='o'>=</span> <span class='sr'>/^([A-Z])?[a-z]+(?(1)[A-Z]|[a-z])$/</span>

<span class='n'>regexp</span> <span class='o'>=~</span> <span class='s2'>&quot;foo&quot;</span>   <span class='c1'>#=&gt; 0</span>
<span class='n'>regexp</span> <span class='o'>=~</span> <span class='s2'>&quot;foO&quot;</span>   <span class='c1'>#=&gt; nil</span>
<span class='n'>regexp</span> <span class='o'>=~</span> <span class='s2'>&quot;FoO&quot;</span>   <span class='c1'>#=&gt; 0</span>
</code></pre></div>
<h2 id='_now_accepts_'><code>Hash#default_proc=</code> now accepts <code>nil</code></h2>

<p>No longer will you have to call <code>hash.default = nil</code> to clear <code>hash.default_proc</code>: now your code will actually make sense!</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>hash</span> <span class='o'>=</span> <span class='p'>{}</span>
<span class='nb'>hash</span><span class='o'>.</span><span class='n'>default_proc</span> <span class='o'>=</span> <span class='no'>Proc</span><span class='o'>.</span><span class='n'>new</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>h</span><span class='p'>,</span><span class='n'>k</span><span class='o'>|</span> <span class='n'>h</span><span class='o'>[</span><span class='n'>k</span><span class='o'>]</span> <span class='o'>=</span> <span class='o'>[]</span><span class='p'>}</span>
<span class='nb'>hash</span><span class='o'>[</span><span class='ss'>:foo</span><span class='o'>]</span> <span class='o'>&lt;&lt;</span> <span class='s2'>&quot;bar&quot;</span>
<span class='nb'>hash</span><span class='o'>[</span><span class='ss'>:foo</span><span class='o'>]</span>                                       <span class='c1'>#=&gt; [&quot;bar&quot;]</span>
<span class='nb'>hash</span><span class='o'>.</span><span class='n'>default_proc</span> <span class='o'>=</span> <span class='kp'>nil</span>
<span class='nb'>hash</span><span class='o'>[</span><span class='ss'>:baz</span><span class='o'>]</span>                                       <span class='c1'>#=&gt; nil</span>
</code></pre></div>
<h2 id='_returns_nil_for_each_value_that_is_outofrange'><code>Array#values_at</code> returns nil for each value that is out-of-range</h2>

<p>Previously <code>#values_at</code> would behave in an unexpected way when given a range, and you&#8217;d only get a single <code>nil</code> for all out-of-range indexes, now you get one for each</p>
<div class='highlight'><pre><code class='ruby'><span class='o'>[</span><span class='mi'>2</span><span class='p'>,</span><span class='mi'>4</span><span class='p'>,</span><span class='mi'>6</span><span class='p'>,</span><span class='mi'>8</span><span class='p'>,</span><span class='mi'>10</span><span class='o'>].</span><span class='n'>values_at</span><span class='p'>(</span><span class='mi'>3</span><span class='o'>.</span><span class='n'>.</span><span class='mi'>7</span><span class='p'>)</span>   <span class='c1'>#=&gt; [8, 10, nil, nil, nil]</span>
</code></pre></div>
<h2 id='option_for__to_expand_braces'>Option for <code>File.fnmatch?</code> to expand braces</h2>

<p>If for some reason you ever find yourself needing to do shell filename glob matches in Ruby you&#8217;ll be happy to know you can now use pattens like {foo,bar}</p>
<div class='highlight'><pre><code class='ruby'><span class='c1'># 3rd argument enables the brace expansion</span>
<span class='no'>File</span><span class='o'>.</span><span class='n'>fnmatch?</span><span class='p'>(</span><span class='s2'>&quot;{foo,bar}&quot;</span><span class='p'>,</span> <span class='s2'>&quot;foo&quot;</span><span class='p'>,</span> <span class='ss'>File</span><span class='p'>:</span><span class='ss'>:FNM_EXTGLOB</span><span class='p'>)</span>   <span class='c1'>#=&gt; true</span>
<span class='no'>File</span><span class='o'>.</span><span class='n'>fnmatch?</span><span class='p'>(</span><span class='s2'>&quot;{foo,bar}&quot;</span><span class='p'>,</span> <span class='s2'>&quot;foo&quot;</span><span class='p'>)</span>                      <span class='c1'>#=&gt; false</span>
<span class='c1'># or together multiple options old-school C style</span>
<span class='n'>casefold_extglob</span> <span class='o'>=</span> <span class='ss'>File</span><span class='p'>:</span><span class='ss'>:FNM_CASEFOLD</span> <span class='o'>|</span> <span class='ss'>File</span><span class='p'>:</span><span class='ss'>:FNM_EXTGLOB</span>
<span class='no'>File</span><span class='o'>.</span><span class='n'>fnmatch?</span><span class='p'>(</span><span class='s2'>&quot;{foo,bar}&quot;</span><span class='p'>,</span> <span class='s2'>&quot;BAR&quot;</span><span class='p'>,</span> <span class='n'>casefold_extglob</span><span class='p'>)</span>    <span class='c1'>#=&gt; true</span>
</code></pre></div>
<h2 id='_calls__on_arguments'><code>Shellwords</code> calls <code>#to_s</code> on arguments</h2>

<p><code>Shellwords#shellescape</code> and <code>#shelljoin</code> will now call <code>#to_s</code> on the arguments, this is particularly useful with <code>Pathname.</code></p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;pathname&quot;</span>
<span class='nb'>require</span> <span class='s2'>&quot;shellwords&quot;</span>

<span class='n'>path</span> <span class='o'>=</span> <span class='no'>Pathname</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='s2'>&quot;~/Library/Application Support/&quot;</span><span class='p'>)</span><span class='o'>.</span><span class='n'>expand_path</span>
<span class='no'>Shellwords</span><span class='o'>.</span><span class='n'>shellescape</span><span class='p'>(</span><span class='n'>path</span><span class='p'>)</span>
<span class='p'>\</span><span class='c1'>#=&gt; &quot;/Users/mat/Library/Application\\ Support&quot;</span>

<span class='no'>Shellwords</span><span class='o'>.</span><span class='n'>join</span><span class='p'>(</span><span class='no'>Pathname</span><span class='o'>.</span><span class='n'>glob</span><span class='p'>(</span><span class='s2'>&quot;/Applications/A*&quot;</span><span class='p'>))</span>
<span class='p'>\</span><span class='c1'>#=&gt; &quot;/Applications/App\\ Store.app /Applications/Automator.app&quot;</span>
</code></pre></div>
<h2 id='_and__now_close_nonstandard_file_descriptors_by_default'><code>system</code> and <code>exec</code> now close non-standard file descriptors by default</h2>

<p>when using <code>exec</code> all open files/sockets, other than <code>STDIN</code>, <code>STDOUT</code> and <code>STDERR</code> will be closed for the new process. This was previously an option with <code>exec(cmd, close_others: true)</code> but it&#8217;s now the default.</p>

<h2 id='protected_methods_treated_like_private_for_'>Protected methods treated like private for <code>#respond_to?</code></h2>

<p>protected methods are now hidden from <code>#respond_to?</code> unless true is passed as a second argument, just like private methods.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='kp'>protected</span>
  <span class='k'>def</span> <span class='nf'>bar</span>
    <span class='s2'>&quot;baz&quot;</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='n'>f</span> <span class='o'>=</span> <span class='no'>Foo</span><span class='o'>.</span><span class='n'>new</span>
<span class='n'>f</span><span class='o'>.</span><span class='n'>respond_to?</span><span class='p'>(</span><span class='ss'>:bar</span><span class='p'>)</span>         <span class='c1'>#=&gt; false</span>
<span class='n'>f</span><span class='o'>.</span><span class='n'>respond_to?</span><span class='p'>(</span><span class='ss'>:bar</span><span class='p'>,</span> <span class='kp'>true</span><span class='p'>)</span>   <span class='c1'>#=&gt; true</span>
</code></pre></div>
<h2 id='_no_longer_calls_'><code>#inspect</code> no longer calls <code>#to_s</code></h2>

<p>Under Ruby 1.9 <code>#inspect</code> gained the odd behaviour of delegating to <code>#to_s</code> if a custom <code>#to_s</code> method had been defined, this has been removed</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='k'>def</span> <span class='nf'>to_s</span>
    <span class='s2'>&quot;foo&quot;</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='no'>Foo</span><span class='o'>.</span><span class='n'>new</span><span class='o'>.</span><span class='n'>inspect</span>   <span class='c1'>#=&gt; &quot;#&lt;Foo:0x007fb4a2887328&gt;&quot;</span>
</code></pre></div>
<h2 id='id8'><code>LoadError#path</code></h2>

<p>Load error now has a <code>#path</code> method to retrieve the path of the file that couldn&#8217;t be loaded. That was already in the message, but now it&#8217;s more easily accessible to code</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>begin</span>
  <span class='n'>require_relative</span> <span class='s2'>&quot;foo&quot;</span>
<span class='k'>rescue</span> <span class='no'>LoadError</span> <span class='o'>=&gt;</span> <span class='n'>e</span>
  <span class='n'>e</span><span class='o'>.</span><span class='n'>message</span>   <span class='c1'>#=&gt; &quot;cannot load such file -- /Users/mat/Dropbox/foo&quot;</span>
  <span class='n'>e</span><span class='o'>.</span><span class='n'>path</span>      <span class='c1'>#=&gt; &quot;/Users/mat/Dropbox/foo&quot;</span>
<span class='k'>end</span>
</code></pre></div>
<h2 id='id9'><code>Process.getsid</code></h2>

<p><code>getsid</code> returns the processes session ID. This only works on unix/linux systems</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Process</span><span class='o'>.</span><span class='n'>getsid</span>   <span class='c1'>#=&gt; 240</span>
</code></pre></div>
<h2 id='id10'><code>Signal.signame</code></h2>

<p>A <code>signame</code> method has been added to get the name for a signal number</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Signal</span><span class='o'>.</span><span class='n'>signame</span><span class='p'>(</span><span class='mi'>9</span><span class='p'>)</span>   <span class='c1'>#=&gt; &quot;KILL&quot;</span>
</code></pre></div>
<h2 id='error_on_trapping_signals_used_internally'>Error on trapping signals used internally</h2>

<p><code>Signal.trap</code> now raises an <code>ArgumentError</code> if you try and trap <code>:SEGV</code>, <code>:BUS</code>, <code>:ILL</code>, <code>:FPE</code>, or <code>:VTALRM</code>. These are used internally by Ruby, so you wouldn&#8217;t be able to trap them anyway.</p>

<h2 id='true_thread_local_variables'>True thread local variables</h2>

<p>As of Ruby 1.9 <code>Thread#[]</code>, <code>#[]=</code>, <code>#keys</code> and <code>#key?</code> would get/set fiber local variables, <code>Thread</code> now gets the methods <code>#thread_variable_get</code>, <code>#thread_variable_set</code>, <code>#thread_variables</code>, <code>#thread_variable?</code> as equivalents that are thread local</p>

<p>Fiber local:</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>b</span> <span class='o'>=</span> <span class='kp'>nil</span>

<span class='n'>a</span> <span class='o'>=</span> <span class='no'>Fiber</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>[</span><span class='ss'>:foo</span><span class='o'>]</span> <span class='o'>=</span> <span class='mi'>1</span>
  <span class='n'>b</span><span class='o'>.</span><span class='n'>transfer</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>[</span><span class='ss'>:foo</span><span class='o'>]</span>
<span class='k'>end</span>

<span class='n'>b</span> <span class='o'>=</span> <span class='no'>Fiber</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>[</span><span class='ss'>:foo</span><span class='o'>]</span> <span class='o'>=</span> <span class='mi'>2</span>
  <span class='n'>a</span><span class='o'>.</span><span class='n'>transfer</span>
<span class='k'>end</span>

<span class='nb'>p</span> <span class='n'>a</span><span class='o'>.</span><span class='n'>resume</span>   <span class='c1'>#=&gt; 1</span>
</code></pre></div>
<p>Thread local:</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>b</span> <span class='o'>=</span> <span class='kp'>nil</span>

<span class='n'>a</span> <span class='o'>=</span> <span class='no'>Fiber</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>.</span><span class='n'>thread_variable_set</span><span class='p'>(</span><span class='ss'>:foo</span><span class='p'>,</span> <span class='mi'>1</span><span class='p'>)</span>
  <span class='n'>b</span><span class='o'>.</span><span class='n'>transfer</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>.</span><span class='n'>thread_variable_get</span><span class='p'>(</span><span class='ss'>:foo</span><span class='p'>)</span>
<span class='k'>end</span>

<span class='n'>b</span> <span class='o'>=</span> <span class='no'>Fiber</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>.</span><span class='n'>thread_variable_set</span><span class='p'>(</span><span class='ss'>:foo</span><span class='p'>,</span> <span class='mi'>2</span><span class='p'>)</span>
  <span class='n'>a</span><span class='o'>.</span><span class='n'>transfer</span>
<span class='k'>end</span>

<span class='nb'>p</span> <span class='n'>a</span><span class='o'>.</span><span class='n'>resume</span>   <span class='c1'>#=&gt; 2</span>
</code></pre></div>
<h2 id='better_error_on_joining_currentmain_thread'>Better error on joining current/main thread</h2>

<p>If you attempt to call <code>#join</code> or <code>#value</code> on the current or main thread you now get a <code>ThreadError</code> raised, which inherits from <code>StandardError,</code> rather than &#8216;fatal&#8217; which inherits from <code>Exception</code>.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>begin</span>
  <span class='no'>Thread</span><span class='o'>.</span><span class='n'>current</span><span class='o'>.</span><span class='n'>join</span>
<span class='k'>rescue</span> <span class='o'>=&gt;</span> <span class='n'>e</span>
  <span class='n'>e</span>   <span class='c1'>#=&gt; #&lt;ThreadError: Target thread must not be current thread&gt;</span>
<span class='k'>end</span>
</code></pre></div>
<h2 id='_changes'><code>Mutex</code> changes</h2>

<p>I can&#8217;t think of a particularly interesting example for this, but you can now check if the current thread owns a mutex.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;thread&quot;</span>

<span class='n'>lock</span> <span class='o'>=</span> <span class='no'>Mutex</span><span class='o'>.</span><span class='n'>new</span>
<span class='n'>lock</span><span class='o'>.</span><span class='n'>lock</span>
<span class='n'>lock</span><span class='o'>.</span><span class='n'>owned?</span>                      <span class='c1'>#=&gt; true</span>
<span class='no'>Thread</span><span class='o'>.</span><span class='n'>new</span> <span class='p'>{</span><span class='n'>lock</span><span class='o'>.</span><span class='n'>owned?</span><span class='p'>}</span><span class='o'>.</span><span class='n'>value</span>   <span class='c1'>#=&gt; false</span>
</code></pre></div>
<p>Also affecting Mutex, methods that change the state of the mutex are no longer allowed in signal handlers: <code>#lock</code>, <code>#unlock</code>, <code>#try_lock</code>, <code>#synchronize</code>, and <code>#sleep</code>.</p>

<p>And apparently <code>#sleep</code> may wake up early, so you&#8217;ll need to double check the correct amount of time has passed if precise timings are important.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>sleep_time</span> <span class='o'>=</span> <span class='mi'>0</span><span class='o'>.</span><span class='mi'>1</span>
<span class='n'>start</span> <span class='o'>=</span> <span class='no'>Time</span><span class='o'>.</span><span class='n'>now</span>
<span class='n'>lock</span><span class='o'>.</span><span class='n'>sleep</span><span class='p'>(</span><span class='n'>sleep_time</span><span class='p'>)</span>
<span class='n'>elapsed</span> <span class='o'>=</span> <span class='no'>Time</span><span class='o'>.</span><span class='n'>now</span> <span class='o'>-</span> <span class='n'>start</span>
<span class='n'>lock</span><span class='o'>.</span><span class='n'>sleep</span><span class='p'>(</span><span class='n'>sleep_time</span> <span class='o'>-</span> <span class='n'>elapsed</span><span class='p'>)</span> <span class='k'>if</span> <span class='n'>elapsed</span> <span class='o'>&lt;</span> <span class='n'>sleep_time</span>
</code></pre></div>
<h2 id='custom_thread_and_fiber_stack_sizes'>Custom thread and fiber stack sizes</h2>

<p>The following environment variables can be set to alter the stack sizes used by threads and fibers. Ruby only checks these as your program starts up.</p>

<ul>
<li><code>RUBY_THREAD_VM_STACK_SIZE</code>: vm stack size used at thread creation. default: 128KB (32bit CPU) or 256KB (64bit CPU).</li>

<li><code>RUBY_THREAD_MACHINE_STACK_SIZE</code>: machine stack size used at thread creation. default: 512KB or 1024KB.</li>

<li><code>RUBY_FIBER_VM_STACK_SIZE</code>: vm stack size used at fiber creation. default: 64KB or 128KB.</li>

<li><code>RUBY_FIBER_MACHINE_STACK_SIZE</code>: machine stack size used at fiber creation. default: 256KB or 256KB.</li>
</ul>

<p>You can get the defaults with</p>
<div class='highlight'><pre><code class='ruby'><span class='ss'>RubyVM</span><span class='p'>:</span><span class='ss'>:DEFAULT_PARAMS</span>   <span class='c1'>#=&gt; {:thread_vm_stack_size=&gt;1048576,</span>
                              <span class='ss'>:thread_machine_stack_size</span><span class='o'>=&gt;</span><span class='mi'>1048576</span><span class='p'>,</span>
                              <span class='ss'>:fiber_vm_stack_size</span><span class='o'>=&gt;</span><span class='mi'>131072</span><span class='p'>,</span>
                              <span class='ss'>:fiber_machine_stack_size</span><span class='o'>=&gt;</span><span class='mi'>524288</span><span class='p'>}</span>
                              
</code></pre></div>
<h2 id='stricter_'>Stricter <code>Fiber#transfer</code></h2>

<p>A fiber that has been transferred to now must be transferred back to, instead of cheating and using <code>resume</code>.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;fiber&quot;</span>

<span class='n'>f2</span> <span class='o'>=</span> <span class='kp'>nil</span>

<span class='n'>f1</span> <span class='o'>=</span> <span class='no'>Fiber</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
  <span class='nb'>puts</span> <span class='s2'>&quot;a&quot;</span>
  <span class='n'>f2</span><span class='o'>.</span><span class='n'>transfer</span>
  <span class='nb'>puts</span> <span class='s2'>&quot;c&quot;</span>
<span class='k'>end</span>

<span class='n'>f2</span> <span class='o'>=</span> <span class='no'>Fiber</span><span class='o'>.</span><span class='n'>new</span> <span class='k'>do</span>
  <span class='nb'>puts</span> <span class='s2'>&quot;b&quot;</span>
  <span class='n'>f1</span><span class='o'>.</span><span class='n'>transfer</span> <span class='c1'># under 1.9 this could have been a #resume</span>
<span class='k'>end</span>

<span class='n'>f1</span><span class='o'>.</span><span class='n'>resume</span>
</code></pre></div>
<h2 id='id11'><code>RubyVM::InstructionSequence</code></h2>

<p><code>RubyVM::InstructionSequence</code> isn&#8217;t new, but it gains a couple of features, and even more helpfully, <a href='http://www.ruby-doc.org/core-2.0/RubyVM/InstructionSequence.html'>detailed documentation</a>.</p>

<p>You can now get the instruction sequence an existing method</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>class</span> <span class='nc'>Foo</span>
  <span class='k'>def</span> <span class='nf'>add</span><span class='p'>(</span><span class='n'>x</span><span class='p'>,</span> <span class='n'>y</span><span class='p'>)</span>
    <span class='n'>x</span> <span class='o'>+</span> <span class='n'>y</span>
  <span class='k'>end</span>
<span class='k'>end</span>

<span class='n'>instructions</span> <span class='o'>=</span> <span class='ss'>RubyVM</span><span class='p'>:</span><span class='ss'>:InstructionSequence</span><span class='o'>.</span><span class='n'>of</span><span class='p'>(</span><span class='no'>Foo</span><span class='o'>.</span><span class='n'>instance_method</span><span class='p'>(</span><span class='ss'>:add</span><span class='p'>))</span>
</code></pre></div>
<p>and when you have that instruction sequence you can get some details about where it was defined</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>instructions</span><span class='o'>.</span><span class='n'>path</span>            <span class='c1'>#=&gt; &quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span>
<span class='n'>instructions</span><span class='o'>.</span><span class='n'>absolute_path</span>   <span class='c1'>#=&gt; &quot;/Users/mat/Dropbox/ruby-2.0.0.rb&quot;</span>
<span class='n'>instructions</span><span class='o'>.</span><span class='n'>label</span>           <span class='c1'>#=&gt; &quot;add&quot;</span>
<span class='n'>instructions</span><span class='o'>.</span><span class='n'>base_label</span>      <span class='c1'>#=&gt; &quot;add&quot;</span>
<span class='n'>instructions</span><span class='o'>.</span><span class='n'>first_lineno</span>    <span class='c1'>#=&gt; 654</span>
</code></pre></div>
<h2 id='id12'><code>ObjectSpace::WeakMap</code></h2>

<p>This class is mainly intended to be part of <code>WeakRef</code>&#8217;s implementation, so you should probably use that (<code>require &quot;weakref&quot;</code>). It holds a weak reference to the objects stored, which means they may be garbage collected.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>map</span> <span class='o'>=</span> <span class='ss'>ObjectSpace</span><span class='p'>:</span><span class='ss'>:WeakMap</span><span class='o'>.</span><span class='n'>new</span>
<span class='c1'># keys can&#39;t be immediate values (numbers, symbols), and you must use the</span>
<span class='c1'># exact same object, not just one that is equal.</span>
<span class='n'>key</span> <span class='o'>=</span> <span class='no'>Object</span><span class='o'>.</span><span class='n'>new</span>

<span class='n'>map</span><span class='o'>[</span><span class='n'>key</span><span class='o'>]</span> <span class='o'>=</span> <span class='s2'>&quot;foo&quot;</span>
<span class='n'>map</span><span class='o'>[</span><span class='n'>key</span><span class='o'>]</span>                <span class='c1'>#=&gt; &quot;foo&quot;</span>
<span class='c1'># force a garbage collection run</span>
<span class='nb'>sleep</span><span class='p'>(</span><span class='mi'>0</span><span class='o'>.</span><span class='mi'>1</span><span class='p'>)</span> <span class='ow'>and</span> <span class='no'>GC</span><span class='o'>.</span><span class='n'>start</span> 
<span class='n'>map</span><span class='o'>[</span><span class='n'>key</span><span class='o'>]</span>                <span class='c1'>#=&gt; nil</span>
</code></pre></div>
<h2 id='top_level_'>Top level <code>define_method</code></h2>

<p><code>define_method</code> can now be used at the top level; it doesn&#8217;t have to be inside a class or module</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Dir</span><span class='o'>[</span><span class='s2'>&quot;config/*.yml&quot;</span><span class='o'>].</span><span class='n'>each</span> <span class='k'>do</span> <span class='o'>|</span><span class='n'>path</span><span class='o'>|</span>
  <span class='sr'>%r{config/(?&lt;name&gt;.*)\.yml\z}</span> <span class='o'>=~</span> <span class='n'>path</span>
  <span class='n'>define_method</span><span class='p'>(</span><span class='ss'>:&quot;</span><span class='si'>#{</span><span class='nb'>name</span><span class='si'>}</span><span class='ss'>_config&quot;</span><span class='p'>)</span> <span class='p'>{</span><span class='no'>YAML</span><span class='o'>.</span><span class='n'>load_file</span><span class='p'>(</span><span class='n'>path</span><span class='p'>)}</span>
<span class='k'>end</span>
</code></pre></div>
<h2 id='no_warning_for_unused_variables_starting_with_'>No warning for unused variables starting with <code>_</code></h2>

<p>This method will generate warnings that the family, port, and host variables are unused.</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>get_ip</span><span class='p'>(</span><span class='n'>sock</span><span class='p'>)</span>
  <span class='n'>family</span><span class='p'>,</span> <span class='n'>port</span><span class='p'>,</span> <span class='n'>host</span><span class='p'>,</span> <span class='n'>address</span> <span class='o'>=</span> <span class='n'>sock</span><span class='o'>.</span><span class='n'>peeraddr</span>
  <span class='n'>address</span>
<span class='k'>end</span>
</code></pre></div>
<p>Using underscores will stop the warnings, but lose the self-documenting nature of the code</p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>get_ip</span><span class='p'>(</span><span class='n'>sock</span><span class='p'>)</span>
  <span class='n'>_</span><span class='p'>,</span> <span class='n'>_</span><span class='p'>,</span> <span class='n'>_</span><span class='p'>,</span> <span class='n'>address</span> <span class='o'>=</span> <span class='n'>sock</span><span class='o'>.</span><span class='n'>peeraddr</span>
  <span class='n'>address</span>
<span class='k'>end</span>
</code></pre></div>
<p>As of Ruby 2.0.0 we can get the best of both worlds by starting the variables with an <code>_</code></p>
<div class='highlight'><pre><code class='ruby'><span class='k'>def</span> <span class='nf'>get_ip</span><span class='p'>(</span><span class='n'>sock</span><span class='p'>)</span>
  <span class='n'>_family</span><span class='p'>,</span> <span class='n'>_port</span><span class='p'>,</span> <span class='n'>_host</span><span class='p'>,</span> <span class='n'>address</span> <span class='o'>=</span> <span class='n'>sock</span><span class='o'>.</span><span class='n'>peeraddr</span>
  <span class='n'>address</span>
<span class='k'>end</span>
</code></pre></div>
<h2 id='_and__removed'><code>Proc#==</code> and <code>#eql?</code> removed</h2>

<p>Under Ruby 1.9.3 <code>Procs</code> with the same body and binding were equal, but you&#8217;d only get procs like this when you&#8217;d cloned one from another. This has now been removed, which is no great loss as it wasn&#8217;t really very useful.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>proc</span> <span class='o'>=</span> <span class='no'>Proc</span><span class='o'>.</span><span class='n'>new</span> <span class='p'>{</span><span class='nb'>puts</span> <span class='s2'>&quot;foo&quot;</span><span class='p'>}</span>

<span class='nb'>proc</span> <span class='o'>==</span> <span class='nb'>proc</span><span class='o'>.</span><span class='n'>clone</span>   <span class='c1'>#=&gt; false</span>
</code></pre></div>
<h2 id='id13'><code>ARGF#each_codepoint</code></h2>

<p><code>ARGF</code> (which is a concatination of the files supplied on the command line) gets an <code>#each_codepoint</code> method like <code>IO</code>.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>count</span> <span class='o'>=</span> <span class='mi'>0</span>
<span class='no'>ARGF</span><span class='o'>.</span><span class='n'>each_codepoint</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>c</span><span class='o'>|</span> <span class='n'>count</span> <span class='o'>+=</span> <span class='mi'>1</span> <span class='k'>if</span> <span class='n'>c</span> <span class='o'>&gt;</span> <span class='mi'>127</span><span class='p'>}</span>
<span class='nb'>puts</span> <span class='s2'>&quot;there are </span><span class='si'>#{</span><span class='n'>count</span><span class='si'>}</span><span class='s2'> non-ascii chacters in the given files&quot;</span>
</code></pre></div>
<h2 id='id14'><code>Time#to_s</code></h2>

<p>The encoding of the string returned from <code>Time#to_s</code> changes from ASCII-8BIT (aka binary) to US-ASCII.</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>Time</span><span class='o'>.</span><span class='n'>now</span><span class='o'>.</span><span class='n'>to_s</span><span class='o'>.</span><span class='n'>encoding</span>   <span class='c1'>#=&gt; #&lt;Encoding:US-ASCII&gt;</span>
</code></pre></div>
<h2 id='random_parameter_of__and__now_called_with__arg'>Random parameter of <code>Array#shuffle!</code> and <code>#sample</code> now called with <code>max</code> arg</h2>

<p>This is a small change, that will probably have no affect on you at all, but now when supplying a random param to the <code>#shuffle!</code>, <code>#shuffle</code>, and <code>#sample</code> methods on <code>Array</code> it&#8217;s now expected to take a <code>max</code> argument, and return an integer between 0 and max, rather than a float between 0 and 1.</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>array</span> <span class='o'>=</span> <span class='o'>[</span><span class='mi'>1</span><span class='p'>,</span> <span class='mi'>3</span><span class='p'>,</span> <span class='mi'>5</span><span class='p'>,</span> <span class='mi'>7</span><span class='p'>,</span> <span class='mi'>9</span><span class='o'>]</span>
<span class='n'>randgen</span> <span class='o'>=</span> <span class='no'>Object</span><span class='o'>.</span><span class='n'>new</span>
<span class='k'>def</span> <span class='nc'>randgen</span><span class='o'>.</span><span class='nf'>rand</span><span class='p'>(</span><span class='n'>max</span><span class='p'>)</span>
  <span class='n'>max</span>                           <span class='c1'>#=&gt; 4</span>
  <span class='mi'>1</span>
<span class='k'>end</span>
<span class='n'>array</span><span class='o'>.</span><span class='n'>sample</span><span class='p'>(</span><span class='ss'>random</span><span class='p'>:</span> <span class='n'>randgen</span><span class='p'>)</span>   <span class='c1'>#=&gt; 3</span>
</code></pre></div>
<h2 id='cgi_html5_tag_builder'>CGI HTML5 tag builder</h2>

<p>CGI from the stdlib gets an HTML5 mode for its tag builder interface.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;cgi&quot;</span>
<span class='n'>cgi</span> <span class='o'>=</span> <span class='no'>CGI</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='s2'>&quot;html5&quot;</span><span class='p'>)</span>
<span class='n'>html</span> <span class='o'>=</span> <span class='n'>cgi</span><span class='o'>.</span><span class='n'>html</span> <span class='k'>do</span>
  <span class='n'>cgi</span><span class='o'>.</span><span class='n'>head</span> <span class='k'>do</span>
    <span class='n'>cgi</span><span class='o'>.</span><span class='n'>title</span> <span class='p'>{</span><span class='s2'>&quot;test&quot;</span><span class='p'>}</span>
  <span class='k'>end</span> <span class='o'>+</span>
  <span class='n'>cgi</span><span class='o'>.</span><span class='n'>body</span> <span class='k'>do</span>
    <span class='n'>cgi</span><span class='o'>.</span><span class='n'>header</span> <span class='p'>{</span><span class='n'>cgi</span><span class='o'>.</span><span class='n'>h1</span> <span class='p'>{</span><span class='s2'>&quot;example&quot;</span><span class='p'>}}</span> <span class='o'>+</span>
    <span class='n'>cgi</span><span class='o'>.</span><span class='n'>p</span> <span class='p'>{</span><span class='s2'>&quot;lorem ipsum&quot;</span><span class='p'>}</span>
  <span class='k'>end</span>
<span class='k'>end</span>
<span class='nb'>puts</span> <span class='n'>html</span>
</code></pre></div>
<p>The old <code>#header</code> method (to send the HTTP header) is now called <code>#http_header</code>, although as long as you&#8217;re not in HTML5 mode it&#8217;s aliased as <code>#header</code> for backwards compatibility.</p>

<h2 id='_and__removed'><code>CSV::dump</code> and <code>::load</code> removed</h2>

<p><code>CSV::dump</code> and <code>CSV::load</code> have been removed. They allowed you to dump/load an array of Ruby objects to a CSV file, and have them serialised and deserialised. They&#8217;ve been removed as they were unsafe.</p>

<h2 id='iconv_removed'>Iconv removed</h2>

<p>Iconv has been removed, in preference of <code>String#encode</code>.</p>

<p>Where previously you might have written something like:</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;iconv&quot;</span>
<span class='no'>Iconv</span><span class='o'>.</span><span class='n'>conv</span><span class='p'>(</span><span class='s2'>&quot;ISO-8859-1&quot;</span><span class='p'>,</span> <span class='s2'>&quot;UTF8&quot;</span><span class='p'>,</span> <span class='s2'>&quot;Résumé&quot;</span><span class='p'>)</span>   <span class='c1'>#=&gt; &quot;R\xE9sum\xE9&quot;</span>
</code></pre></div>
<p>You&#8217;d now write</p>
<div class='highlight'><pre><code class='ruby'><span class='s2'>&quot;Résumé&quot;</span><span class='o'>.</span><span class='n'>encode</span><span class='p'>(</span><span class='ss'>Encoding</span><span class='p'>:</span><span class='ss'>:ISO_8859_1</span><span class='p'>)</span>        <span class='c1'>#=&gt; &quot;R\xE9sum\xE9&quot;</span>
</code></pre></div>
<h2 id='syck_removed'>Syck removed</h2>

<p>The Syck YAML parser has been removed in favour of Psych (libyaml bindings), and Ruby now comes bundled with libyaml. The YAML interface in Ruby stays the same, so this shouldn&#8217;t have and affect on your code.</p>

<h2 id='id15'><code>io/console</code></h2>

<p><code>io/console</code> isn&#8217;t new, but the <a href='http://www.ruby-doc.org/stdlib-2.0/libdoc/io/console/rdoc/IO.html'>documentation</a> is so now you can actually figure out how to use it. The Ruby 2.0.0 NEWS file claims the <code>IO#cooked</code> and <code>#cooked!</code> methods are new, but they seem to be available in 1.9.3.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;io/console&quot;</span>
<span class='no'>IO</span><span class='o'>.</span><span class='n'>console</span><span class='o'>.</span><span class='n'>raw!</span>
<span class='c1'># console in now in raw mode, disabling line editing and echoing</span>
<span class='no'>IO</span><span class='o'>.</span><span class='n'>console</span><span class='o'>.</span><span class='n'>cooked!</span>
<span class='c1'># back in cooked mode, line editing works like normal</span>
</code></pre></div>
<p><code>#raw!</code> and <code>#raw</code> get two new arguments, <code>min</code> and <code>time</code>.</p>
<div class='highlight'><pre><code class='ruby'><span class='no'>IO</span><span class='o'>.</span><span class='n'>console</span><span class='o'>.</span><span class='n'>raw!</span><span class='p'>(</span><span class='ss'>min</span><span class='p'>:</span> <span class='mi'>5</span><span class='p'>)</span> <span class='c1'># reading from console buffers for 5 chars</span>
<span class='no'>IO</span><span class='o'>.</span><span class='n'>console</span><span class='o'>.</span><span class='n'>raw!</span><span class='p'>(</span><span class='ss'>min</span><span class='p'>:</span> <span class='mi'>5</span><span class='p'>,</span> <span class='ss'>time</span><span class='p'>:</span> <span class='mi'>1</span><span class='p'>)</span> <span class='c1'># read after 1 second if buffer not full</span>
</code></pre></div>
<h2 id='id16'><code>io/wait</code></h2>

<p><code>io/wait</code> adds a <code>#wait_writeable</code> method that will block till an IO can be written to. <code>#wait</code> gets renamed to <code>#wait_readable,</code> and there&#8217;s a <code>#wait</code> alias for backwards compatibility.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;io/wait&quot;</span>
<span class='n'>timeout</span> <span class='o'>=</span> <span class='mi'>1</span>
<span class='no'>STDOUT</span><span class='o'>.</span><span class='n'>wait_writable</span><span class='p'>(</span><span class='n'>timeout</span><span class='p'>)</span>   <span class='c1'>#=&gt; #&lt;IO:&lt;STDOUT&gt;&gt;</span>
</code></pre></div>
<h2 id='_performance_improvements'><code>Net::HTTP</code> performance improvements</h2>

<p><code>Net::HTTP</code> now automatically requests and decompresses gzip and deflate compression by default. This should play very nicely with the new non-GIL-blocking Zlib.</p>

<p>SSL sessions are also now reused, cutting down on time spent negotiating connections.</p>

<h2 id='_can_specify_the_hostport_to_connect_from'><code>Net::HTTP</code> can specify the host/port to connect from</h2>

<p>If for some reason you need to specify the local host/port to connect from, along with the host/port to connect to, you now can</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>http</span> <span class='o'>=</span> <span class='ss'>Net</span><span class='p'>:</span><span class='ss'>:HTTP</span><span class='o'>.</span><span class='n'>new</span><span class='p'>(</span><span class='n'>remote_host</span><span class='p'>,</span> <span class='n'>remote_port</span><span class='p'>)</span>
<span class='n'>http</span><span class='o'>.</span><span class='n'>local_host</span> <span class='o'>=</span> <span class='n'>local_host</span>
<span class='n'>http</span><span class='o'>.</span><span class='n'>local_port</span> <span class='o'>=</span> <span class='n'>local_port</span>
<span class='n'>http</span><span class='o'>.</span><span class='n'>start</span> <span class='k'>do</span>
  <span class='c1'># ...</span>
<span class='k'>end</span>
</code></pre></div>
<h2 id='_can_act_like_a_hash'><code>OpenStruct</code> can act like a hash</h2>

<p><code>OpenStruct</code> gains <code>#[]</code>, <code>#[]=</code> and <code>#each_pair</code> methods so it can be used like a hash.</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;ostruct&quot;</span>

<span class='n'>o</span> <span class='o'>=</span> <span class='no'>OpenStruct</span><span class='o'>.</span><span class='n'>new</span>
<span class='n'>o</span><span class='o'>.</span><span class='n'>foo</span> <span class='o'>=</span> <span class='s2'>&quot;test&quot;</span>
<span class='n'>o</span><span class='o'>[</span><span class='ss'>:foo</span><span class='o'>]</span>               <span class='c1'>#=&gt; &quot;test&quot;</span>
<span class='n'>o</span><span class='o'>[</span><span class='ss'>:bar</span><span class='o'>]</span> <span class='o'>=</span> <span class='s2'>&quot;example&quot;</span>
<span class='n'>o</span><span class='o'>.</span><span class='n'>bar</span>                 <span class='c1'>#=&gt; example</span>
</code></pre></div>
<p>It also gains <code>#hash</code> and <code>#eql?</code> methods, which are used internally by <code>Hash</code> to check equality. These allow it to play better as a hash key, with equal objects acting as the same key.</p>

<h2 id='timeout_support_in_'>Timeout support in <code>Resolv</code></h2>

<p><code>Resolv</code> now supports custom timeouts</p>
<div class='highlight'><pre><code class='ruby'><span class='nb'>require</span> <span class='s2'>&quot;resolv&quot;</span>

<span class='n'>resolver</span> <span class='o'>=</span> <span class='ss'>Resolv</span><span class='p'>:</span><span class='ss'>:DNS</span><span class='o'>.</span><span class='n'>new</span>
<span class='n'>resolver</span><span class='o'>.</span><span class='n'>timeouts</span> <span class='o'>=</span> <span class='mi'>1</span> <span class='c1'># 1 second</span>
<span class='n'>resolver</span><span class='o'>.</span><span class='n'>getaddress</span><span class='p'>(</span><span class='s2'>&quot;globaldev.co.uk&quot;</span><span class='p'>)</span><span class='o'>.</span><span class='n'>to_s</span>   <span class='c1'>#=&gt; &quot;204.232.175.78&quot;</span>
</code></pre></div>
<p>It will also take an array, and work its way through the timeouts, retrying after each. You could implement exponential back-off with</p>
<div class='highlight'><pre><code class='ruby'><span class='n'>resolver</span><span class='o'>.</span><span class='n'>timeouts</span> <span class='o'>=</span> <span class='o'>[</span><span class='mi'>1</span><span class='o'>].</span><span class='n'>tap</span> <span class='p'>{</span><span class='o'>|</span><span class='n'>a</span><span class='o'>|</span> <span class='mi'>5</span><span class='o'>.</span><span class='n'>times</span> <span class='p'>{</span><span class='n'>a</span><span class='o'>.</span><span class='n'>push</span><span class='p'>(</span><span class='n'>a</span><span class='o'>.</span><span class='n'>last</span> <span class='o'>*</span> <span class='mi'>2</span><span class='p'>)}}</span>
</code></pre></div>
<h2 id='and_thats_it'>And that&#8217;s it&#8230;</h2>

<p>Please let me know if there&#8217;s anything missing or incorrect here. Also, don&#8217;t forget that <a href='/jobs/'>we&#8217;re hiring</a>&#8230;</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/ApGgzP9XYQs" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/03/ruby-2-0-0-in-detail/</feedburner:origLink></item>
    
      <item>
        <title>Celebrating our first year in London</title>
        <pubDate>Wed, 06 Mar 2013 00:00:00 -0800</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/AGp-j1WwRqY/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/03/celebrating-our-first-year-in-london/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>A year ago today we officially opened the company&amp;#8217;s London office, just opposite Waterloo Station. Starting off with six developers and engineers who were previously working in our Windsor office, we&amp;#8217;ve now more than doubled in size.A key reason for opening the office was making it easier to attract London-based...</description>
        <content:encoded><![CDATA[<img class='alignleft' title='The Waterloo team celebrating with cake and party poppers' src='/images/uploads/2013/03/waterloo-first-year.gif' />
<p><a href='http://globalpersonals.co.uk/press-release/global-personals-creates-20-jobs-for-new-london-office/'>A year ago today</a> we officially opened the company&#8217;s London office, just opposite Waterloo Station. Starting off with six developers and engineers who were previously working in our Windsor office, we&#8217;ve now more than doubled in size.</p>

<p>A key reason for opening the office was making it easier to attract London-based staff or those who would find it difficult to get to our headquarters in Windsor. With easy access from across the South-East, we now have staff travelling in from across London, Essex, Sussex and Surrey.</p>

<p>In May 2012, following Global Personals&#8217; <a href='http://globalpersonals.co.uk/press-release/global-personals-ltd-acquires-market-leading-freemium-brand-smooch-com/'>acquisition of Woowise</a>, we were joined by Marcus, James, Gordon and Jeff, swelling our numbers to thirteen. Matching the facilities in Windsor, the team enjoy Friday bacon sandwiches, a fridge with cans of soft drinks and of course the Xbox 360 for post-work games.</p>

<p>It&#8217;s a great location with excellent views across London and we expect to keep adding to our numbers in London throughout 2013 and beyond.</p>

<p>So happy first birthday to us! Here&#8217;s to the next 12 months in London.</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/AGp-j1WwRqY" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/03/celebrating-our-first-year-in-london/</feedburner:origLink></item>
    
      <item>
        <title>Happy debugging with JavaScript source maps</title>
        <pubDate>Fri, 25 Jan 2013 00:00:00 -0800</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/Mqb9HpmF6A0/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/01/happy-debugging-with-javascript-source-maps/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>I&amp;#8217;ve discussed previously the fact that we are gradually trying to improve the JavaScript behind the White Label Dating platform. The most recent step in this process has been to investigate the use of source maps when it comes to debugging our scripts.What are source maps?Obviously, our JavaScript library is...</description>
        <content:encoded><![CDATA[<p>I&#8217;ve <a href='/2012/11/maintaining-consistent-javascript-with-jslint/'>discussed previously</a> the fact that we are gradually trying to improve the JavaScript behind the <a href='http://www.whitelabeldating.com/'>White Label Dating</a> platform. The most recent step in this process has been to investigate the use of source maps when it comes to debugging our scripts.</p>

<h3 id='what_are_source_maps'>What are source maps?</h3>

<p>Obviously, our JavaScript library is served in the form of a single, minified file on production servers. During development, it&#8217;s a different story, with the various scripts that make up that library all included individually, in their original uncompressed form. This means it&#8217;s easy to identify any JavaScript issues during development, because most browser development tools will indicate at least a file name and line number when they encounter an error. But if we experience a live issue, that debugging becomes a whole lot harder. Have a look at this screenshot:</p>

<p><img src='/images/uploads/2013/01/js-unmapped-error.png' alt='Unmapped JavaScript error' /></p>

<p>How are you meant to know where the error actually occurred? This is where source maps come in. A source map is effectively a technique to map a minified file back to its original, uncompressed state. For an excellent introduction to JavaScript source maps, I recommend that you read the <a href='http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/'>HTML5 Rocks article</a> on the subject. What we want to achieve is this:</p>

<p><img src='/images/uploads/2013/01/js-mapped-error.png' alt='Mapped JavaScript error' /></p>

<p>Notice how much easier it is to see the error. The clever thing is that the browser has actually downloaded the <em>minified file</em>, so the average user will be completely unaffected by the addition of a source map. The browser will only download the source map and unminified file when you ask it to (currently, that&#8217;s done by opening the developer tools of Chrome or Safari and enabling source maps).</p>

<h3 id='generating_our_source_map'>Generating our source map</h3>

<p>The first step was to integrate the generation of our source map into our build process. We use <a href='http://gruntjs.com/'>Grunt</a> to produce production builds of our JavaScript library, and we use the Google Closure Compiler for minification. Fortuantely, the Closure Compiler can also generate source maps. There is already an <a href='https://github.com/gmarty/grunt-closure-compiler'>excellent Grunt plugin</a> that adds Google Closure support, so we use that too. All that remains is to add a section to the Grunt script that uses Closure to produce a source map:</p>
<div class='highlight'><pre><code class='javascript'> 
<span class='nx'>grunt</span><span class='p'>.</span><span class='nx'>initConfig</span><span class='p'>({</span>
    <span class='s2'>&quot;closure-compiler&quot;</span><span class='o'>:</span> <span class='p'>{</span>
        <span class='nx'>sourcemap</span><span class='o'>:</span> <span class='p'>{</span>
            <span class='nx'>js</span><span class='o'>:</span> <span class='s2'>&quot;build/library.js&quot;</span><span class='p'>,</span>
            <span class='nx'>jsOutputFile</span><span class='o'>:</span> <span class='s2'>&quot;build/library.min.js&quot;</span><span class='p'>,</span>
            <span class='nx'>options</span><span class='o'>:</span> <span class='p'>{</span>
                <span class='nx'>create_source_map</span><span class='o'>:</span> <span class='s2'>&quot;build/library.min.js.map&quot;</span><span class='p'>,</span>
                <span class='nx'>source_map_format</span><span class='o'>:</span> <span class='s2'>&quot;V3&quot;</span>             
            <span class='p'>}</span>        
        <span class='p'>}</span>     
    <span class='p'>}</span> 
<span class='p'>});</span>
</code></pre></div>
<p>That works well so now any time we run our build script, we get a source map file in the output directory. Unfortunately, the Closure Compiler is not yet capable of adding the reference to the source map to the minified script which means we add it ourselves. The current source maps specification gives the following format. It&#8217;s just a normal JavaScript comment so browsers that don&#8217;t support source maps will completely ignore it:</p>

<p><div class='highlight'><pre><code class='javascript'><span class='c1'>//@ sourceMappingURL=library.min.js.map </span>
</code></pre></div></p>

<p>Adding this comment manually after each build would be annoying. Luckily, it&#8217;s very easy to extend Grunt so we&#8217;ve written <a href='https://github.com/jamesallardice/grunt-append-sourcemapping'>a simple plugin</a> to handle it for us. By including that plugin in our build script, all we have to do is add another small section to the Grunt config:</p>
<div class='highlight'><pre><code class='javascript'><span class='nx'>grunt</span><span class='p'>.</span><span class='nx'>initConfig</span><span class='p'>({</span>
    <span class='s2'>&quot;closure-compiler&quot;</span><span class='o'>:</span> <span class='p'>{</span>
        <span class='c1'>// Closure compiler configuration</span>
    <span class='p'>},</span>
    <span class='s2'>&quot;append-sourcemapping&quot;</span><span class='o'>:</span> <span class='p'>{</span>
        <span class='nx'>main</span><span class='o'>:</span> <span class='p'>{</span>
            <span class='nx'>files</span><span class='o'>:</span> <span class='p'>{</span>
                <span class='s2'>&quot;build/library.min.js&quot;</span><span class='o'>:</span> <span class='s2'>&quot;library.min.js.map&quot;</span>
            <span class='p'>}</span>
        <span class='p'>}</span>
    <span class='p'>}</span>
<span class='p'>});</span>
</code></pre></div>
<h3 id='fighting_with_internet_explorer'>Fighting with Internet Explorer</h3>

<p>It was never going to be <em>that</em> simple. Turns out that there&#8217;s a problem using source maps in all versions of Internet Explorer under certain circumstances. If you&#8217;ve ever seen or used <a href='http://msdn.microsoft.com/en-us/library/ie/121hztk3%28v=vs.94%29.aspx'>conditional JavaScript compilation</a> in IE, you may have recognised the format of that source map include comment earlier.</p>

<p>If a library with a source mapping comment is included in a page after conditional compilation has been turned on (it&#8217;s turned on with a comment containing the string <code>@cc_on @</code>), you&#8217;re going to end up with JavaScript errors. Internet Explorer will attempt to parse your source map comment as part of the program, and will almost certainly fail because the source map URL (<code>library.min.js.map</code> in the example above) will not be a valid identifier.</p>

<p>For more details of the issue, see <a href='http://bugs.jquery.com/ticket/13274'>this jQuery bug report</a>. That ticket also details a very simple workaround. By simply wrapping the source mapping comment in a multiline comment, Internet Explorer will not attempt to parse it, even when conditional compilation is active. All we had to do was make a little change to our Grunt plugin to get the comment output looking like this:</p>
<div class='highlight'><pre><code class='javascript'><span class='cm'>/*</span>
<span class='cm'>//@ sourceMappingURL=library.min.js.map</span>
<span class='cm'>*/</span>
</code></pre></div>
<p>And that&#8217;s all there is to it. We now have working source maps in WebKit browsers, and Firefox support is supposed to be in the works. Over the next few months, we should see more and more chatter about this emerging technique so get a head start and implement source maps in your JavaScript libraries as soon as possible.</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/Mqb9HpmF6A0" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/01/happy-debugging-with-javascript-source-maps/</feedburner:origLink></item>
    
      <item>
        <title>Migrating memcached</title>
        <pubDate>Thu, 03 Jan 2013 00:00:00 -0800</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/HJV1qVodyoc/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2013/01/migrating-memcached/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>As part of the pre-Christmas push we rolled out a series of infrastructure improvements including both new additional servers and new servers to replace old ones. One set of servers to be upgraded were our cache servers. These have two roles day-to-day, firstly they&amp;#8217;re our Akamai (CDN) origin servers and...</description>
        <content:encoded><![CDATA[<p>As part of the pre-Christmas push we rolled out a series of infrastructure improvements including both new additional servers and new servers to replace old ones. One set of servers to be upgraded were our cache servers. These have two roles day-to-day, firstly they&#8217;re our <a href='http://www.akamai.com/'>Akamai</a> (CDN) origin servers and secondly they store our primary memcached instances.</p>

<p>Each server has multiple instances of memcached running on different ports. There are multiple sets for both the &#8220;data&#8221; and &#8220;view&#8221; segments. Each of the new servers has 64GB RAM.</p>

<h2 id='migration_challenges'>Migration Challenges</h2>

<p>The main challenges when planning to migrate the data is mitigating the impact on the platform. memcached is a core element. It&#8217;s used to store HTML fragment caches and various parts of both site and member data.</p>

<p>There is a tight line between getting the migration completed versus keeping the application as quick as possible during the whole procedure.</p>

<h2 id='approaches'>Approaches</h2>

<p>There are a few approaches which are briefly outlined below:</p>

<ul>
<li><strong>Big Bang</strong>. Update all the configuration files and simply push that code live. This has a huge hit on performance as all the new instances are cold, it is however the quickest option.</li>

<li><strong>Migration instance by instance.</strong> Each instance would be moved and relevant configuration files pushed live. This way only 1 or X instances is &#8220;cold&#8221;. This limits impact, but, also takes time as only 1 instance can be done at any one time.</li>

<li><strong>Write to both.</strong> The application code could be altered to make all writes to both the existing set of instances and the new. This isn&#8217;t great as we&#8217;d need a full QA cycle to validate the code works. It&#8217;s also something we&#8217;d have to implement then pull back out down the line.</li>

<li><strong>Mirror traffic.</strong> Similar to the above, but, this time lower down the stack. Essentially duplicate all the TCP level traffic so it warms in parallel and keeps both instances in sync meaning new writes, deletes occur on both existing and new sets.</li>
</ul>

<h2 id='solution'>Solution</h2>

<p>In the end the best solution which minimised the impact to the platform was to mirror all the traffic to the existing instances across to the new instances. <code>tcpcopy</code> helped us to get this done. As well as migrating data, <code>tcpcopy</code> could be used to load test, stress test and benchmark.</p>

<p>The plan involved running the <code>tcpcopy</code> for 24 hours, see how full the new instances reached then decided if another 24 hours should elapse before the code changes to point at new instances are deployed.</p>

<p>There would be some data &#8220;missing&#8221; however all freqently used data keys, core and shared information will all exist and as such mitigate the performance concerns.</p>

<h3 id='id3'><code>tcpcopy</code></h3>

<p>Installing <a href='https://github.com/wangbin579/tcpcopy'><code>tcpcopy</code></a> is pretty straight forward. Assuming all requirements are in place:</p>
<div class='highlight'><pre><code class='bash'>wget --no-check-certificate <span class='se'>\</span>
  https://github.com/downloads/wangbin579/tcpcopy/tcpcopy-0.6.5.tar.gz <span class='o'>&amp;&amp;</span> <span class='se'>\</span>
  tar xvfz tcpcopy-0.6.5.tar.gz <span class='o'>&amp;&amp;</span> <span class='nb'>cd </span>tcpcopy-0.6.5 <span class='o'>&amp;&amp;</span> <span class='se'>\</span>
  ./configure <span class='o'>&amp;&amp;</span> make <span class='o'>&amp;&amp;</span> make install
</code></pre></div>
<p>Once that&#8217;s installed on your target server (new cache servers) you&#8217;ll need to setup the iptables rules. Note there are a couple of extra&#8217;s here to ensure that connections from the localhost and from the office IP were not queued to allowing monitoring.</p>
<div class='highlight'><pre><code class='bash'>modprobe ip_queue;
iptables -A OUTPUT -o lo -j ACCEPT;
iptables -A OUTPUT -d 1.2.3.4/32 -j ACCEPT;
iptables -A OUTPUT -p tcp --match multiport --sports 11211:11212 -j QUEUE;
</code></pre></div>
<p>You can then fire up the intercepter, the <code>-d</code> option backgrounds the process as a daemon.</p>
<div class='highlight'><pre><code class='bash'>intercept -d
</code></pre></div>
<p>Next you&#8217;ll need to head over to the source servers. In our case this is the existing cache servers.</p>
<div class='highlight'><pre><code class='bash'>tcpcopy -d -x 11211-192.168.2.184:11211
tcpcopy -d -x 11212-192.168.2.184:11212
</code></pre></div>
<p>The format of the copy is <code>localport-targetip:targetport</code>. You can tweak with more options as well, see the <a href='https://github.com/downloads/wangbin579/tcpcopy/TCPCopy_0.6.5_Manual.pdf'>manual</a> for full details. You can also include logging if needed by using <code>-l
/path/to/log</code>.</p>

<h3 id='monitoring'>Monitoring</h3>

<p>In order to see how the copies were going 3 monitoring methods were used.</p>

<h4 id='direct_monitoring_via_'>Direct monitoring via <code>telnet</code></h4>
<div class='highlight'><pre><code class='text'>[root@server ~] telnet 0 11211
Trying 0.0.0.0...
Connected to 0.
Escape character is &#39;^]&#39;.
stats
STAT pid 1234
STAT uptime 1234
STAT time 111111111
...
</code></pre></div>
<h4 id='ruby_key_dumper'>Ruby key dumper</h4>

<p>This small <a href='https://gist.github.com/1365005'>Ruby key dumper</a> allows you to dump out a selection of the keys. It&#8217;s not great and memcached doesn&#8217;t allow a full dump of keys in anyway. It allows you to see what&#8217;s there and validate it&#8217;s content though.</p>

<h4 id='overall_instance_stats_from_'>Overall instance stats from <code>memcache-top</code></h4>

<p>This is a perl program available on <a href='http://code.google.com/p/memcache-top/'>google code</a> which allows you monitor a given set of instances, much like regular top.</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/HJV1qVodyoc" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2013/01/migrating-memcached/</feedburner:origLink></item>
    
      <item>
        <title>Discovering and fixing a bug in JSLint and JSHint</title>
        <pubDate>Wed, 05 Dec 2012 00:00:00 -0800</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/jGPZqruHJsM/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2012/12/discovering-and-fixing-a-bug-in-jslint-and-jshint/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>JSLint, and the popular fork of it JSHint, are static analysis tools for JavaScript programs. They are designed to alert the developer to parts of code that could potentially cause problems, be that a fatal syntax error or a lack of convention that could cause maintenance problems in the future.Recently...</description>
        <content:encoded><![CDATA[<p>JSLint, and the popular fork of it JSHint, are static analysis tools for JavaScript programs. They are designed to alert the developer to parts of code that could potentially cause problems, be that a fatal syntax error or a lack of convention that could cause maintenance problems in the future.</p>

<p>Recently I&#8217;ve spent a lot of time playing around with JSLint and JSHint, both for my work on <a href='http://jslinterrors.com'>jslinterrors.com</a> and in preparation for the use of <a href='http://globaldev.co.uk/2012/11/maintaining-consistent-javascript-with-jslint/'>JSLint to enforce a coding style</a>. During this investigation, I came across a potentially nasty little bug in both tools.</p>

<h3 id='a_bit_of_background'>A bit of background</h3>

<p>In JavaScript (as in most languages) you cannot use a reserved word as an identifier. For example, the following will fail with a syntax error:</p>
<div class='highlight'><pre><code class='javascript'><span class='kd'>var</span> <span class='k'>default</span> <span class='o'>=</span> <span class='mi'>10</span><span class='p'>;</span>
</code></pre></div>
<p>In the most widely supported iteration of the language, ECMAScript 3, it is also illegal to use a reserved word as an object property identifier:</p>
<div class='highlight'><pre><code class='javascript'><span class='kd'>var</span> <span class='nx'>myObject</span> <span class='o'>=</span> <span class='p'>{</span>
    <span class='k'>default</span><span class='o'>:</span> <span class='mi'>10</span>
<span class='p'>};</span>
</code></pre></div>
<p>However, in the most recent version of the language specification <a href='http://es5.github.com/'>ECMAScript 5</a>, which now enjoys widespread support across the major browsers, as well as in Node.js, a change has been made to allow the use of reserved words as object property identifers. This means that the above example is actually valid and will not cause a syntax error in any modern browser.</p>

<p>The details of the change can be seen if we delve into the ECMAScript spec. First, here&#8217;s the relevant snippets from the <a href='http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf'>old ES3 version</a>:</p>
<div class='highlight'>
<em>ObjectLiteral</em> :<br />
&nbsp;&nbsp;&nbsp;&nbsp;{ }<br />
&nbsp;&nbsp;&nbsp;&nbsp;{ <em>PropertyNameAndValueList</em> }<br /><br />
<em>PropertyNameAndValueList</em> :<br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>PropertyName</em> : <em>AssignmentExpression</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>PropertyNameAndValueList</em> , <em>PropertyName</em> : <em>AssignmentExpression</em><br /><br />
<em>PropertyName</em> :<br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>Identifier</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>StringLiteral</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>NumericLiteral</em>
</div>
<p>The important part from that snippet is the <em>Identifier</em> production of <em>PropertyName</em>. If we look at the grammar for identifiers, we see that reserved words are not allowed:</p>
<div class='highlight'>
<em>Identifier</em> ::<br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>IdentifierName</em> but not <em>ReservedWord</em>
</div>
<p>If we now look at the <a href='http://es5.github.com/#A.1'>same section from the ES5 spec</a>, we can see the slight change to the grammar for <em>PropertyName</em>:</p>
<div class='highlight'>
<em>PropertyName</em> :<br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>IdentifierName</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>StringLiteral</em><br />
&nbsp;&nbsp;&nbsp;&nbsp;<em>NumericLiteral</em>
</div>
<p>It&#8217;s a small change, but a significant one. The <em>Identifer</em> production has been replaced with <em>IdentifierName</em>, which is effectively the same as <em>Identifier</em> but without the restriction on reserved words. It&#8217;s this change that means in ES5-supporting environments we are able to use reserved words as object property identifiers.</p>

<h3 id='how_do_jslint_and_jshint_fit_into_this'>How do JSLint and JSHint fit into this?</h3>

<p>Both JSLint and JSHint will warn you about <a href='http://jslinterrors.com/expected-an-identifier-and-instead-saw-a-a-reserved-word/'>the use of a reserved word as an identifier</a> by default. If you are writing code that will only run in ES5-supporting environments, you can set an option (the <code>es5</code> option) that surpresses this warning:</p>
<div class='highlight'><pre><code class='javascript'><span class='cm'>/*jslint es5: true */</span>
<span class='kd'>var</span> <span class='nx'>myObject</span> <span class='o'>=</span> <span class='p'>{</span>
    <span class='k'>default</span><span class='o'>:</span> <span class='mi'>10</span> <span class='c1'>// Valid JavaScript, does not cause a JSLint/JSHint error</span>
<span class='p'>};</span>
</code></pre></div>
<p>This is useful, expected behaviour. However, when the <code>es5</code> option is set, JSLint and JSHint will also allow you to use a reserved word as a variable or function identifier, as well as an object property identifier:</p>
<div class='highlight'><pre><code class='javascript'><span class='cm'>/*jslint es5: true */</span>
<span class='kd'>var</span> <span class='k'>default</span> <span class='o'>=</span> <span class='mi'>10</span><span class='p'>;</span> <span class='c1'>// Invalid JavaScript, does not cause a JSLint/JSHint error</span>
</code></pre></div>
<p>This is incorrect and will actually throw a syntax error in all environments, regardless of ES5 support. This is a problem, especially if you rely on JSLint/JSHint to give confidence in your code (perhaps as part of your build process), as you could easily end up releasing broken code.</p>

<h3 id='tracking_down_the_cause_of_the_bug'>Tracking down the cause of the bug</h3>

<p>Following through the <a href='https://github.com/douglascrockford/JSLint/'>JSLint source</a> led me to the <code>property_name</code> function, which is called when the parser encounters a object property identifier. The first thing it does is call another function, <code>optional_identifier</code>, passing through <code>true</code> as its lone argument. This is the only call to <code>optional_identifier</code> that ever passes through an argument and the function signature for <code>optional_identifier</code> does not contain any formal parameters.</p>

<p>At this point, I am guessing that when JSLint was written this was a slight oversight and the author simply forgot to handle this specific case within the <code>optional_identifier</code> function. A quick look at the implementation of the function reveals that no arguments are considered, and the error in question is raised if the identifier is a reserved word and the <code>es5</code> option does not evaluate to <code>true</code>:</p>
<div class='highlight'><pre><code class='javascript'><span class='kd'>function</span> <span class='nx'>optional_identifier</span><span class='p'>()</span> <span class='p'>{</span>
    <span class='k'>if</span> <span class='p'>(</span><span class='nx'>next_token</span><span class='p'>.</span><span class='nx'>identifier</span><span class='p'>)</span> <span class='p'>{</span>
        <span class='nx'>advance</span><span class='p'>();</span>
        <span class='k'>if</span> <span class='p'>(</span><span class='nx'>option</span><span class='p'>.</span><span class='nx'>safe</span> <span class='o'>&amp;&amp;</span> <span class='nx'>banned</span><span class='p'>[</span><span class='nx'>token</span><span class='p'>.</span><span class='nx'>string</span><span class='p'>])</span> <span class='p'>{</span>
            <span class='nx'>warn</span><span class='p'>(</span><span class='s1'>&#39;adsafe_a&#39;</span><span class='p'>,</span> <span class='nx'>token</span><span class='p'>);</span>
        <span class='p'>}</span> <span class='k'>else</span> <span class='k'>if</span> <span class='p'>(</span><span class='nx'>token</span><span class='p'>.</span><span class='nx'>reserved</span> <span class='o'>&amp;&amp;</span> <span class='o'>!</span><span class='nx'>option</span><span class='p'>.</span><span class='nx'>es5</span><span class='p'>)</span> <span class='p'>{</span>
            <span class='nx'>warn</span><span class='p'>(</span><span class='s1'>&#39;expected_identifier_a_reserved&#39;</span><span class='p'>,</span> <span class='nx'>token</span><span class='p'>);</span> <span class='c1'>// This line raises the error in question</span>
        <span class='p'>}</span>
        <span class='k'>return</span> <span class='nx'>token</span><span class='p'>.</span><span class='nx'>string</span><span class='p'>;</span>
    <span class='p'>}</span>
<span class='p'>}</span>
</code></pre></div>
<p>We can make a simple change to this function to take into account the argument passed in by the call mentioned earlier and ensure JSLint continues to raise this error when it encounters a reserved word as a variable or function identifier:</p>
<div class='highlight'><pre><code class='javascript'><span class='kd'>function</span> <span class='nx'>optional_identifier</span><span class='p'>(</span><span class='nx'>prop</span><span class='p'>)</span> <span class='p'>{</span> <span class='c1'>// Added a formal parameter</span>
    <span class='k'>if</span> <span class='p'>(</span><span class='nx'>next_token</span><span class='p'>.</span><span class='nx'>identifier</span><span class='p'>)</span> <span class='p'>{</span>
        <span class='nx'>advance</span><span class='p'>();</span>
        <span class='k'>if</span> <span class='p'>(</span><span class='nx'>option</span><span class='p'>.</span><span class='nx'>safe</span> <span class='o'>&amp;&amp;</span> <span class='nx'>banned</span><span class='p'>[</span><span class='nx'>token</span><span class='p'>.</span><span class='nx'>string</span><span class='p'>])</span> <span class='p'>{</span>
            <span class='nx'>warn</span><span class='p'>(</span><span class='s1'>&#39;adsafe_a&#39;</span><span class='p'>,</span> <span class='nx'>token</span><span class='p'>);</span>
        <span class='p'>}</span> <span class='k'>else</span> <span class='k'>if</span> <span class='p'>(</span><span class='nx'>token</span><span class='p'>.</span><span class='nx'>reserved</span> <span class='o'>&amp;&amp;</span> <span class='p'>(</span><span class='o'>!</span><span class='nx'>prop</span> <span class='o'>||</span> <span class='o'>!</span><span class='nx'>option</span><span class='p'>.</span><span class='nx'>es5</span><span class='p'>))</span> <span class='p'>{</span> <span class='c1'>// Handle that parameter</span>
            <span class='nx'>warn</span><span class='p'>(</span><span class='s1'>&#39;expected_identifier_a_reserved&#39;</span><span class='p'>,</span> <span class='nx'>token</span><span class='p'>);</span>
        <span class='p'>}</span>
        <span class='k'>return</span> <span class='nx'>token</span><span class='p'>.</span><span class='nx'>string</span><span class='p'>;</span>
    <span class='p'>}</span>
<span class='p'>}</span>
</code></pre></div>
<p>The fix is pretty much the same for JSHint, since it started life as a straight fork of JSLint and much of the internals remain unchanged. I opened a <a href='https://github.com/jshint/jshint/issues/744'>pull request</a> in JSHint on GitHub, which has since been merged in, meaning this is no longer an issue in JSHint. The problem remains in JSLint for now, but we hope to get a patch submitted to it in the near future.</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/jGPZqruHJsM" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2012/12/discovering-and-fixing-a-bug-in-jslint-and-jshint/</feedburner:origLink></item>
    
      <item>
        <title>Maintaining Consistent JavaScript with JSLint</title>
        <pubDate>Tue, 20 Nov 2012 00:00:00 -0800</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/OW0VPRiGJQY/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2012/11/maintaining-consistent-javascript-with-jslint/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>Why?As you can probably imagine, the White Label Dating platform contains a lot of JavaScript. It&amp;#8217;s been written by many people over many years, and when you have numerous people working on the same code you&amp;#8217;re always likely to end up with a bit of a mess. The code may...</description>
        <content:encoded><![CDATA[<h2 id='why'>Why?</h2>

<p>As you can probably imagine, the <a href='http://www.whitelabeldating.com/'>White Label Dating</a> platform contains a lot of JavaScript. It&#8217;s been written by many people over many years, and when you have numerous people working on the same code you&#8217;re always likely to end up with a bit of a mess. The code may work as intended. It may even follow a lot of best practices and be easily extensible. But it almost certainly won&#8217;t be nice to look at, or easy to read, and that can often lead to problems with maintenance in the future.</p>

<p>In an attempt to make our JavaScript easier on the eye, we have started using Douglas Crockford&#8217;s <a href='http://jslint.com/'>JSLint tool</a> to enforce a consistent style throughout. I&#8217;m sure you have your own opinions on JSLint, and I&#8217;m well aware that many developers (myself included) think that some of the rules that JSLint wants you to follow are verging on ridiculous (for example, forbidding the use of the <code>++</code> increment operator). However, by fine-tuning the various options available to you, and putting up with the occasional annoyance, you can use JSLint to your advantage and end up with a JavaScript code base that is much easier to maintain.</p>

<h2 id='configuring_jslint'>Configuring JSLint</h2>

<p>We decided to configure JSLint on a per-file basis. This way, every file can have its own options which allows us a bit of flexibility. If you want to allow the use of the increment and decrement operators in a file, and you want common browser properties like <code>document</code> to appear predefined (JSLint will throw <code>undefined</code> errors if they don&#8217;t), you can do so with a <code>jslint</code> directive at the top of the code:</p>
<div class='highlight'><pre><code class='javascript'><span class='cm'>/*jslint plusplus: true, browser: true */</span>
</code></pre></div>
<p>There are some JSLint options that allow you to get away with sloppy code formatting (such as the <code>white</code> option, which will allow &#8220;messy white space&#8221;). Unfortunately, there is no way to enforce that this option is always turned on, so we have to simply make developers aware that such options must not be set in any files. If they were, it would kind of defeat the point.</p>

<h2 id='enforcing_the_use_of_jslint'>Enforcing the use of JSLint</h2>

<p>Now that we&#8217;ve defined the standards for JavaScript development, we need a way to enforce them. It&#8217;s very easy to simply paste your JavaScript into the online tool at on the <a href='http://jslint.com/'>JSLint website</a>, but that&#8217;s a bit too much work. Instead, we wanted to automate the process, and we have achieved this with a Git pre-commit hook, which prevents anyone from committing JavaScript that doesn&#8217;t pass JSLint when it should.</p>

<p>There&#8217;s a couple of things that are required for our hook to work. The first is <a href='http://nodejs.org/'>Node.js</a> (along with <a href='https://npmjs.org/'>NPM</a>, the Node Package Manager). Once you&#8217;ve got those up and running, you can globally install <a href='https://github.com/reid/node-jslint'>node-jslint</a> which will add the executable to your path:</p>
<div class='highlight'><pre><code class='bash'>npm install -g jslint
</code></pre></div>
<p>Now we can run JSLint from the terminal, so we can get on with our Git hook. It will run JSLint against all JavaScript files staged for commit, and even provide colour-coded feedback. It needs to be placed in <code>repository/.git/hooks/pre-commit</code>:</p>
<div class='highlight'><pre><code class='bash'><span class='c'>#!/bin/sh</span>

<span class='nv'>files</span><span class='o'>=</span><span class='k'>$(</span>git diff --cached --name-only --diff-filter<span class='o'>=</span>ACM | grep <span class='s2'>&quot;.js$&quot;</span><span class='k'>)</span>
<span class='k'>if</span> <span class='o'>[</span> <span class='s2'>&quot;$files&quot;</span> <span class='o'>=</span> <span class='s2'>&quot;&quot;</span> <span class='o'>]</span>; <span class='k'>then </span>
<span class='k'>    </span><span class='nb'>exit </span>0 
<span class='k'>fi</span>

<span class='nv'>pass</span><span class='o'>=</span><span class='nb'>true</span>

<span class='nb'>echo</span> <span class='s2'>&quot;\nValidating JavaScript:\n&quot;</span>

<span class='k'>for </span>file in <span class='k'>${</span><span class='nv'>files</span><span class='k'>}</span>; <span class='k'>do</span>
<span class='k'>    </span><span class='nv'>result</span><span class='o'>=</span><span class='k'>$(</span>jslint <span class='k'>${</span><span class='nv'>file</span><span class='k'>}</span> | grep <span class='s2'>&quot;${file} is OK&quot;</span><span class='k'>)</span>
    <span class='k'>if</span> <span class='o'>[</span> <span class='s2'>&quot;$result&quot;</span> !<span class='o'>=</span> <span class='s2'>&quot;&quot;</span> <span class='o'>]</span>; <span class='k'>then</span>
<span class='k'>        </span><span class='nb'>echo</span> <span class='s2'>&quot;\t\033[32mJSLint Passed: ${file}\033[0m&quot;</span>
    <span class='k'>else</span>
<span class='k'>        </span><span class='nb'>echo</span> <span class='s2'>&quot;\t\033[31mJSLint Failed: ${file}\033[0m&quot;</span>
        <span class='nv'>pass</span><span class='o'>=</span><span class='nb'>false</span>
<span class='nb'>    </span><span class='k'>fi</span>
<span class='k'>done</span>

<span class='nb'>echo</span> <span class='s2'>&quot;\nJavaScript validation complete\n&quot;</span>

<span class='k'>if</span> ! <span class='nv'>$pass</span>; <span class='k'>then</span>
<span class='k'>    </span><span class='nb'>echo</span> <span class='s2'>&quot;\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again.\n&quot;</span>
    <span class='nb'>exit </span>1
<span class='k'>else</span>
<span class='k'>    </span><span class='nb'>echo</span> <span class='s2'>&quot;\033[42mCOMMIT SUCCEEDED\033[0m\n&quot;</span>
<span class='k'>fi</span>
</code></pre></div>
<h2 id='keeping_track_of_our_hook'>Keeping track of our hook</h2>

<p>One of the problems with Git hooks is that they are not part of the repository itself (since they live within the <code>.git</code> directory). We don&#8217;t expect to be changing our hook regularly, but it would be nice to have the hook itself under version control. We achieved this by simply finding a suitable location in the repository, and creating the hook script there. When anyone sets up their development environment, a single command can be run to activate the hook, by symlinking to the hook file from the Git hooks directory:</p>
<div class='highlight'><pre><code class='bash'>ln -s /path/to/repo/pre-commit-jslint /path/to/repo/.git/hooks/pre-commit
</code></pre></div>
<p>In the near future we would like to get this step integrated into a more general &#8220;development environment setup&#8221; script, so that new starters or anyone setting up a clean dev environment can kick off one script and come back later to a fully working local copy of the app.</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/OW0VPRiGJQY" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2012/11/maintaining-consistent-javascript-with-jslint/</feedburner:origLink></item>
    
      <item>
        <title>Our Response to BritRuby's Cancellation</title>
        <pubDate>Mon, 19 Nov 2012 00:00:00 -0800</pubDate>
        <link>http://feedproxy.google.com/~r/globaldev/~3/bwboAjOKY9Q/</link>
        <guid isPermaLink="false">http://globaldev.co.uk/2012/11/our-response-to-britruby-s-cancellation/</guid>
        <dc:creator>
            
        </dc:creator>
        <description>Last night, the team behind the upcoming and much anticipated BritRuby Conference announced that the event has officially been cancelled.A number of reasons have been cited, all of which stem from claims on Twitter that the speaker lineup lacks racial and gender diversity and in turn, according to the team...</description>
        <content:encoded><![CDATA[<p>Last night, the team behind the upcoming and much anticipated BritRuby Conference announced that the event has <a href='http://2013.britruby.com/'>officially been cancelled</a>.</p>
<img src='https://si0.twimg.com/profile_images/2864875750/c5686a0e47b534eaba729d566f441df8.png' align='right' style='margin: 0 0 0 1em;' />
<p>A number of reasons have been cited, all of which stem from claims on Twitter that the speaker lineup lacks racial and gender diversity and in turn, according to the team at BritRuby, this has resulted in one or more of the sponsors pulling out.</p>

<p>globaldev were proud to have been announced as one of the sponsors for BritRuby less than two weeks ago. We were delighted to put our name behind a large-scale Ruby event where the intention was to help improve the Ruby developer community throughout the UK which is no mean feat given the immense disparity between the significant number of companies seeking talented developers within this niche and the unfortunate rarity of high quality Ruby developers on the job market.</p>

<p>The cancellation of BritRuby is a shame and we want to state categorically that globaldev <a href='https://twitter.com/globaldev/status/270452324525305857'>backed BritRuby 100%</a>. We want nothing more than to see the community become more diverse in every shape and form and we sincerely believe that events of the scale of BritRuby are the perfect platform to make more and more people aware of the huge demand in this particular area of development.</p><img src="http://feeds.feedburner.com/~r/globaldev/~4/bwboAjOKY9Q" height="1" width="1"/>]]></content:encoded>
      <feedburner:origLink>http://globaldev.co.uk/2012/11/our-response-to-britruby-s-cancellation/</feedburner:origLink></item>
    
  </channel>
</rss>
