Destructive to the Original String. (String#insert)
Just as an FYI this function is destructive to the original String object. name = 'draper' #=> "draper" name.insert( 0, 'don ' ) #=> 'don draper' name #=> 'don draper'
View ArticleUse Join to Turn Array Items into a String. (Array#to_s)
If you’re looking to take an array like [ 'don', 'draper' ] And get 'don draper' Then use join instead: [ 'don', 'draper' ].join( ' ' ) #=> 'don draper'
View Articleferragamo (Dir#mkdir)
Salvatore <a href=“http://www.ferragamochaussures.com”>ferragamo pas cher, 30 ~ 70% de rabais! Salvatore ferragamo chaussures!Bienvenue à notre Salvatore ferragamo en ligne, la spécialité de...
View ArticleBasicObject.new (BasicObject#new)
Instantiates a new blank object (devoid of methods). The only class method of class BasicObject. see “ri BasicObject” eg, > o=BasicObject.new (Object doesn’t support #inspect) > > o.methods...
View ArticleDir (Dir#exists?)
The documentation is using File.directory?(“/path/to/directory”), but the method being referred to is Dir.exists?(). Dir.exists?(".") => true The source code is the same as File.directory?().
View ArticleStarts with a Capital Letter (String#start_with?)
(or any regular expression you’d like) 'Abracadabra'[0..0] =~ /[A-Z]/ # => true
View ArticleUndefined Method `mktmpdir' for Dir:Class (Dir#mktmpdir)
Be sure to require 'tmpdir' before using it. Read more at http://mikbe.tk/2011/03/07/temporary-directory.
View ArticleStarts with capital letter alternative (String#start_with?)
Just adding an anchor to the regular expression seems simpler (and was faster in my benchmarks, not that that matters much): 'Abracadabra' =~ /^[A-Z]/
View Articlerindex with identically array elements (Array#rindex)
Code Example a = [1,1,1] a.rindex( a.min ) #=> 2
View Articlemore_than? instance method (Array)
Over the weekend I kept running into instances where I was writing code like this: Code example arr = ['hello', 'world'] if arr.length > 2 # do stuff else # do something else end So I ended up...
View ArticleTest if an array is included in another (Array#include?)
Array class Array def included_in? array array.to_set.superset?(self.to_set) end end [1,2,4].included_in?([1,10,2,34,4]) #=> true
View Articlesee also – similar methods (DateTime#strftime)
See also Time#strftime and Date#strftime . (They work similarly, but have different APIdock notes.)
View Articlesee also – similar methods (Date#strftime)
See also Time#strftime and DateTime#strftime . (They work similarly, but have different APIdock notes.)
View Articlesee also – similar methods (Time#strftime)
See also DateTime#strftime and Date#strftime . (They work similarly, but have different APIdock notes.)
View ArticleAssignment using 'key: value' (Hash#[])
Another shorthand way of assigning key, value pairs: Hash[one: 1, two: 2] #=> {:one=>1, :two=>2}
View ArticleLong-wanted functional extension (Enumerable#each_with_object)
This is pretty nice method allowing you to build stuff in a functional way. Lets say you want to build a hash from an array, keyed by array object, where each value is the number of same objects in...
View ArticleWhat it do? (Hash#to_yaml)
For those favoring YAML outputs, this methods simply and recursively outputs the keys and values in YAML (into a String) for your pleasure.
View Article__callee__ and __method__ both return symbol when originally defined, not...
There has been some indication that __callee__ is intended to return the symbol with which the method was actually invoked, whereas __method__ returns name with which the method was originally...
View ArticleReports originally defined method names, not invoked names in Ruby 1.9.x...
In Ruby 1.8.7, the reported method names were those of the methods actually invoked, so if #b was an alias for #a, and #b was called, it would be reported as “… in `b’”. In Ruby 1.9, the same...
View Article
More Pages to Explore .....