ruby Questions

11

Solved

What is the proper syntax for a method that checks a string for a pattern, and returns true or false if the regex matches? Basic idea: def has_regex?(string) pattern = /something/i return strin...
Hapless asked 7/2, 2010 at 0:12

5

Solved

class A def a_method #.. end end class B < A def method_1 # ... a_method end def method_2 # ... a_method end # ... def method_n # ... a_method end end The a_method ocassion...
Emarginate asked 15/9, 2016 at 9:11

3

Solved

I'm building a simple app in ruby using the Sinatra framework. It's mainly "get" based - most requests will be for listing data. However there are a couple of key screens in the app that will colle...
Eustasius asked 12/7, 2012 at 11:47

2

Solved

I have a fat multi-tenant Rails app on Apache + mod_passenger that outputs product prices from a PostgreSQL table as follows: Table "public.products" Column | Type id | bigint name | character var...
Nursemaid asked 27/9, 2018 at 13:18

3

Solved

Does anyone have a plugin or macro to replace matching { braces } with do and end in Vim? Preferably turning a single-line statement like this: foo.each { |f| f.whatever } into: foo.each do |f|...
Krakow asked 16/3, 2013 at 2:38

3

Solved

I know that there is no "official" support from Jetbrains. How can I workaround this? I just need a syntax highlighting level of support for ruby. Thanks in advance.
Pareu asked 16/10, 2013 at 16:50

3

I am upgrading one of my news app to Rails 6.0.0. While working around I got a problem using Rich Text. My app is pointing the rich text body field instead of the my existing table body field. Is...
Melindamelinde asked 29/8, 2019 at 3:55

5

Here's a code example: class Foo def self.create_method def example_method "foo" end end private create_method end Foo.public_instance_methods(false) # => [:example_method] Is it po...
Alvinaalvine asked 7/4, 2015 at 13:24

6

Solved

i'm using RubyMine 6.3 buth I have some problems with debugger C:\Ruby200\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-debug...
Psychobiology asked 3/5, 2014 at 9:17

5

Solved

I am trying to stub Time.now in RSpec as follows: it "should set the date to the current date" do @time_now = Time.now Time.stub!(:now).and_return(@time_now) @thing.capture_item("description")...
Urge asked 30/8, 2015 at 19:42

6

Solved

To test, whether a constant (say: a class) is known at a certain point in the code, I can write for instance: if defined? :String or I can write if self.class.const_defined? :String Is there ...
Burhans asked 2/6, 2020 at 14:5

9

Solved

I have a bunch of automatically generated JSON files that I want to store in version control. The problem is that each time the files are serialized, the attributes come out in a different order, m...
Michaeline asked 25/9, 2012 at 14:9

9

I have tried to install several versions of ruby (2.5.5, 2.6.6, 2.7.4, 3.0.0) and in all cases it has given the same error, of course with each version, in this example I only put the error for ver...
Designed asked 10/5, 2022 at 0:3

3

Solved

Is there a way to add timeout options in this simple get method? I am using Faraday 3.3. Faraday.get(url) After searching around, I can only apply timeout options after I initiate a connection ...
Clef asked 28/8, 2015 at 13:35

6

Solved

Rails has built in log filtering so you don't log passwords and credit cards. Works great for that but when you want to trigger a custom log (like to email) and send your own params or other data a...
Powe asked 29/8, 2011 at 15:56

5

Solved

Is there anyway to write the following code in Ruby without writing the file to disk? temp_file = 'path/to/file.csv' users = [[email protected], [email protected]] CSV.open(temp_file, "...
Briannebriano asked 23/1, 2013 at 20:27

7

Solved

Is there a way to remove the BOM from a UTF-8 encoded file? I know that all of my JSON files are encoded in UTF-8, but the data entry person who edited the JSON files saved it as UTF-8 with the BO...
Maiduguri asked 16/2, 2011 at 1:15

2

Solved

Learning Ruby for the first time to automate cleaning up some CSV files. I've managed to piece together the script below from other SO questions but for some reason the script does not read the f...
Mudskipper asked 8/8, 2019 at 18:26

4

Solved

When I run the command npx react-native run-ios in my terminal on my Mac I receive the error CompileC /Users/jessicageorge-mannella/Library/Developer/Xcode/DerivedData/AwesomeProject-ctnixtnnzajiwu...
Execrative asked 2/4, 2023 at 2:28

4

Solved

Say I have a method MyKlass#do_thing that I want to call exactly once in a test (because it might change a state), and that should return true on successful state change and false otherwise. I want...
Tricia asked 13/3, 2018 at 12:43

2

Here's some info: I do not have admin privileges to my machine. I'm running macOS Catalina 10.15.5. I use zshell. I have Xcode command-line tools 11.5 but NOT XCode itself. I'm running Ruby v2.6.3...
Carline asked 11/3, 2021 at 21:23

4

Solved

I have a strange bundle update issue with the dependency of net-pop. I manually updated all gems via bundle update GEM. Everything works so far. My CI builds and tests jobs are green. But: When I n...
Allyson asked 13/6, 2024 at 10:59

2

I'm trying to change a function — which currently only accepts a URL (path) string — to make it more flexible, so that it will also accept as input the same arguments that you can pass to url_for. ...
Vaquero asked 8/1, 2019 at 5:28

5

Solved

Let's say I have an array of names, along with a regex union of them: match_array = [/Dan/i, /Danny/i, /Daniel/i] match_values = Regexp.union(match_array) I'm using a regex union because the actua...
Boast asked 9/7, 2024 at 2:52

4

Python has the Counter class in the collections module. It is a class for counting hashable objects. E.g.: cnt = Counter() cnt['Anna'] += 3 cnt['John'] += 2 cnt['Anna'] += 4 print(cnt) => Count...
Gooseherd asked 20/11, 2015 at 13:54

© 2022 - 2025 — McMap. All rights reserved.