Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Last active December 23, 2015 17:29
Show Gist options
  • Save pjaspers/6669390 to your computer and use it in GitHub Desktop.
Save pjaspers/6669390 to your computer and use it in GitHub Desktop.
ruby-2.1.0-preview1 changes in code samples.
# def foo now returns a symbol instead of nil, allowing for something like this
class Thing
protected def some;end
protected def like; end
def it; end
protected def hot; end
end
Thing.new.protected_methods
=> [:some, :like, :hot]
# Refinements, example from [here](http://www.rubyinside.com/ruby-refinements-an-overview-of-a-new-proposed-ruby-feature-3978.html)
module TimeExtensions
refine Fixnum do
def minutes; self * 60; end
end
end
class MyApp
using TimeExtensions
def initialize
p 2.minutes
end
end
MyApp.new # => 120
p 2.minutes # => NoMethodError
# F suffix will make `String` frozen.
"bla"f.gsub!("l", "k")
# RuntimeError: can't modify frozen String
# Complete list [here](https://github.com/ruby/ruby/blob/v2_1_0_preview1/NEWS)
@DefV
Copy link

DefV commented Sep 23, 2013

"bla"f really looks like a syntax error to me

@pjaspers
Copy link
Author

Had the exact same feeling.

@pjaspers
Copy link
Author

Much better list here: http://rkh.im/ruby-2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment