<<

<<(text) Instance Public methods Appends text

chdir

Dir.chdir( [ string] ) â 0Dir.chdir( [ string] ) {| path | block } â anObject Class Public methods Changes the current working directory of the process to the given string. When called without an argument, changes the directory to the value of the environment variable HOME, or LOGDIR. SystemCallError (probably Errno::ENOENT) if the target directory does not exist. If a block is given, it is passed the name of the new current directory, and the block is executed with that as the c

classify

classify() Instance Public methods Classifies the set by the return value of the given block and returns a hash of {value => set of elements} pairs. The block is called once for each element of the set, passing the element as parameter. e.g.: require 'set' files = Set.new(Dir.glob("*.rb")) hash = files.classify { |f| File.mtime(f).year } p hash # => {2000=>#<Set: {"a.rb", "b.rb"}>, # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>, # 2

add_column_sql

add_column_sql(table_name, column_name, type, options = {}) Instance Protected methods

get_one_optional_argument

get_one_optional_argument() Instance Public methods Get a single optional argument from the command line. If more than one argument is given, return only the first. Return nil if none are given.

id

id() Instance Public methods

connection

connection() Instance Public methods Retrieve the connection associated with the current thread, or call checkout to obtain one if necessary. connection can be called any number of times; the connection is held in a hash keyed by the thread id.

change_column

change_column(table_name, column_name, type, options = {}) Instance Public methods Changes the column's definition according to the new options. See ActiveRecord::ConnectionAdapters::TableDefinition#column for details of the options you can use. change_column(:suppliers, :name, :string, limit: 80) change_column(:accounts, :description, :text)

flatten

ary.flatten â new_aryary.flatten(level) â new_ary Instance Public methods Returns a new array that is a one-dimensional flattening of self (recursively). That is, for every element that is an array, extract its elements into the new array. The optional level argument determines the level of recursion to flatten. s = [ 1, 2, 3 ] #=> [1, 2, 3] t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]] a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10] a.flat

from_json

from_json(json, include_root=include_root_in_json) Instance Public methods Sets the model attributes from a JSON string. Returns self. class Person include ActiveModel::Serializers::JSON attr_accessor :name, :age, :awesome def attributes=(hash) hash.each do |key, value| send("#{key}=", value) end end def attributes instance_values end end json = { name: 'bob', age: 22, awesome:true }.to_json person = Person.new person.from_json(json) # => #<P