ruby

Find records in deeply nested associations with rails

▼魔方 西西 提交于 2021-02-05 07:14:25
问题 I have the following models: class Book < ApplicationRecord has_many :chapters end class Chapter < ApplicationRecord belongs_to :book has_many :pages end class Page < ApplicationRecord belongs_to :chapter has_many :paragraphs end class Paragrpah < ApplicationRecord belongs_to :page end Now I want to get a list of all paragraphs in a specific book. Something like: @parapgraphs = Paragraph.pages.chapters.book.where(:title => 'My Book') When I do this, I get: undefined method 'chapters' for

UML sequence diagram - how to represent method arguments that instantiate objects

北城以北 提交于 2021-02-05 05:57:28
问题 I'm not sure how to represent something like the following in a sequence diagram (in Ruby): class FirstClass def process thing = SecondClass.new('string argument', third_class, 2) end def third_class ThirdClass.new('another string argument',) end end The first message in the sequence is a call to an instance of FirstClass, and the part that's tripping me up is how to represent the ThirdClass.new being passed as an argument to the SecondClass initializer. 回答1: Basically you just show how and

Why can't I instantiate Integer class in Ruby?

二次信任 提交于 2021-02-05 04:58:12
问题 I thought all classes in Ruby can be instantiated. What's preventing Integer class from being instantiated with new method? Integer.new # => NoMethodError: undefined method `new' for Integer:Class 回答1: There are a few of those. Besides Integer , Float , and Symbol , you can't create a new instance of TrueClass , FalseClass and NilClass too. These classes (and their respective instances) are all special in Ruby and are handled in a specific way internally. With small Integers for example, Ruby

Why can't I instantiate Integer class in Ruby?

佐手、 提交于 2021-02-05 04:58:00
问题 I thought all classes in Ruby can be instantiated. What's preventing Integer class from being instantiated with new method? Integer.new # => NoMethodError: undefined method `new' for Integer:Class 回答1: There are a few of those. Besides Integer , Float , and Symbol , you can't create a new instance of TrueClass , FalseClass and NilClass too. These classes (and their respective instances) are all special in Ruby and are handled in a specific way internally. With small Integers for example, Ruby

Install Ruby 2.2 on Mac OSX Catalina with ruby-install

时光总嘲笑我的痴心妄想 提交于 2021-02-05 02:41:08
问题 Here's what I get when I try to install Ruby 2.2: $ ruby-install ruby 2.2.10 # ... >>> Compiling ruby 2.2.10 ... CC = clang LD = ld LDSHARED = clang -dynamic -bundle CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -pipe

Install Ruby 2.2 on Mac OSX Catalina with ruby-install

不问归期 提交于 2021-02-05 02:40:06
问题 Here's what I get when I try to install Ruby 2.2: $ ruby-install ruby 2.2.10 # ... >>> Compiling ruby 2.2.10 ... CC = clang LD = ld LDSHARED = clang -dynamic -bundle CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -pipe

Cannot find origin object in Rails project

百般思念 提交于 2021-02-04 21:45:45
问题 I just inherited a Rails app for a new gig. Thee code is insane and heavily buried in gem logic so VERY difficult and un-rails-like to navigate. I am having a terrible time tracking down the following logic. @navigator ||= BitPlayer::Navigator.new(current_participant) I have searched everywhere (in app as well as gem dirs) for a BitPlayer class/object as well as Navigator and cannot find a thing. I am thinking I don't understand the fundamental composition of the line. Can someone point me in

Calling Instance Variables without @

主宰稳场 提交于 2021-02-04 21:42:09
问题 I'm new to Ruby programming and I've seen a few examples now where an instance variable is being called without the "@" symbol in front of it. I'm not sure if this because the method is being called and the instance variable is stored in the method as a result of a attr_reader in the class or if because I have the wrong understanding of instance variables. Here's an example of what I'm referring to taken from Russ Olsen's Eloquent Ruby, where the @unique array has the size method called on it

Calling Instance Variables without @

人盡茶涼 提交于 2021-02-04 21:42:06
问题 I'm new to Ruby programming and I've seen a few examples now where an instance variable is being called without the "@" symbol in front of it. I'm not sure if this because the method is being called and the instance variable is stored in the method as a result of a attr_reader in the class or if because I have the wrong understanding of instance variables. Here's an example of what I'm referring to taken from Russ Olsen's Eloquent Ruby, where the @unique array has the size method called on it

Unable to push a custom gem to heroku master

亡梦爱人 提交于 2021-02-04 21:37:39
问题 I have created a simple custom gem in 'gemz' folder and configured in gemfile ('checkpercentage', '~>0.1.0') and it works fine in my application but can't deploy it to heroku. I'm getting the following error when trying to push my updates into my master branch at Heroku. my Ruby version: ruby 2.1.1p76 (2014-02-24 revision 45161) [i686-linux] Error: nci@nci-VirtualBox:~/Zacchi/kuizu$ git push heroku master remote: Compressing source files... done. remote: Building source: remote: remote: -----