Special Character Methods

  • aimeebooth
  • 3171 views
Hall-pass

Oops, a subscription is required to view this video. You can enroll now to watch, or try out all that Code School has to offer with a free two-day Hall Pass.

Resources

Comments

Matthew Fritz said

Thank you for this. As a new rubyist it certainly answered one of my "newbie" ruby questions.

Faculty

Code School Support said

Hi Andrew! Ruby doesn't provide any method like sort!?, and even though you could probably write your own, it's not really a good idea to create a method like that. If you want to check if changes were made in calling sort!, you can create a method like sorted? which could contain sort! and compare the original array to the sorted array.

Andrew Tinkov said

Nice screencast, thx! I have a question. Can these special character methods be combined? Lets say we have method "sort", which sorts an array and returns true if changes where made and false otherwise. Can I check the result of the sort action by calling "sort!?" ?

Faculty

Aimee Booth Simone said

Thanks, Charles! You're right - the ability to convert booleans to be_true is part of the RSpec DSL. We talk about this in the Testing With RSpec, if you want to learn more about it.

Charles Green said

Great video. You mentioned that the boolean operator "?" is just part of a naming convention. Is this different then in Rails w/ RSpec where it can be converted into "be_true" or is that just part of their DSL?

Boris said

Awesome! Thank you.

About

As a Rubyist you're likely to encounter some strange methods ending in question marks and exclamation marks. What are those and how should you approach them?

Subscribe