$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')
If you need the table names:
$ ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')
If you need the table names:
$ ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
| class Object | |
| def send_through(object, *args) | |
| object.dispatcher_for(self).call(self, *args) | |
| end | |
| end | |
| module Dispatcher | |
| class DispatcherNotFound < StandardError; end | |
| def self.extended(klass) |
| "ab" | |
| "a | |
| b" |
| def store(provider, board, status) | |
| # @connection is a PG::Connection object | |
| # @logger is a Logger object | |
| # The part before `.each` is inconsequential, it's just a prepared statement and we're | |
| # iterating over the results. | |
| @connection.exec_prepared(TYPE, [provider, board].concat(statement status)).each do |row| | |
| # Ignore this | |
| @logger.debug(Harvester::Runner) do | |
| Scrawl.new(label: "insert", table: TABLE, id: row["id"]) |
| class Array | |
| def number_of_items_deleted(char) | |
| self.size - self.tap { |o| o.delete(char) }.size | |
| end | |
| end | |
| puts %w(a b a d t r).number_of_items_deleted 'a' | |
| # >> 2 |
Originally published in June 2008
When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.
To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.
Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.
| require 'socket' | |
| require 'fiber' | |
| #A list of readables and writables for IO.select, and which fiber is waiting for which IO | |
| watch = { | |
| readable: {}, #{io => fiber} | |
| writable: {} | |
| } |
Enumerable is a module, and Enumerator is a class. So that should tell you a lot out the the box. Enumerable is a set of behaviors and functionality you'd want to add to a class. The Enumerator class is something you get objects from itself.
| class Wrong | |
| def method_missing(m, *) | |
| if m =~ /\Ahello_(.+)\z/ | |
| puts "Hello, #{$1.capitalize}" | |
| else | |
| super | |
| end | |
| end | |
| end |
Enumerable#to_a says, that it can take arguments also. Lets try
(1..4).to_a(1,2)
#ArgumentError: wrong number of arguments (2 for 0)Oops! Why then error ? Because Enumerable#to_a called actually Range#each which don't accept any arguments. Now look the below code :-