spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » RUBY » Page 1
Ruby OCI8 - bind optional parameters to Oracle Stored procedure
cursor = conn.parse('BEGIN foo(:p_1, :p_2, p_opt_2 => :p_opt_2); END;') cursor.bind_param(:p_1, 'some string', String) cursor.bind_param(:p_2, 'some other string', String) cursor.bind_param(:p_opt_2, 'some value', String) cursor.exec more simply: conn.exec('BEGIN foo(:p_1, :p_2, p_opt_2 => :p_opt_2); END;', 'some string', 'some other string', 'some value')

Categories : Ruby

How to install the app only once for the suite
I found this thread on the calabash-android google group that sounds like what you are asking for. It says delete these 3 lines uninstall_apps install_app(ENV["TEST_APP_PATH"]) install_app(ENV["APP_PATH"]) Then make sure to install app when you start your tests. For the full post see this link https://groups.google.com/forum/#!topic/calabash-android/Ql3iluRMijg The reply by Preeti Jind

Categories : Ruby

Different test unit output in Rubymine and console
When I run unit tests from RubyMine How do you configure it? If you configure it as a simple ruby script or rake task in Run, you will get wrong results (it seems merely tracking execute time instead of checking if tests pass). Instead you define run/debug configuration in Test::Unit/Shoulda/MiniTest. P.S. I'm using RubyMine 7.0.

Categories : Ruby

Can Rake run each test in a separate Ruby instance?
Instead of using Rake::TestTask, you could define a test task in your Rakefile that loops through each test file and runs them with sh like this: task :test do libs = ['lib', '/usr/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib', '/usr/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb'] test_files = FileList['test/**/test*.rb'] test_files.each do |test_file|

Categories : Ruby

Ruby strftime in UK format i.e. dd/mm/yy
Have look at easy_dates gem gem install gemcutter gem tumble gem install easy_dates you don't have to worry about formatting your dates continually with strftime.

Categories : Ruby

Accessing hash in Ruby like objects in Coffeescript
Ruby doesn't have any built-in solution; your solution is the right way to do it. firstname, lastname, @email = params.values_at(:firstname, :lastname, :email) If you happen to know the hash is an ordered hash, and contains just the values you want, and in the order you want, then you can get all the values like this: # Suppose params = { # firstname: …, # lastname: …, # email:

Categories : Ruby

How do I correct my script, that it doesn't matter what file name has the .xml that is uploaded?
When uploading a file, you don't need to save it to disk on the server - simply read the upload IO (see here): view.erb: <%= form_tag({action: :upload}, multipart: true) do %> <%= file_field_tag 'xml' %> <% end %> <%= form_for @upload do |f| %> <%= f.file_field :xml %> <% end %> controller: uploaded_io = params[:upload][:xml] string_complete = uploaded

Categories : Ruby

Ruby: Tests not runing
You need to use a class that inherits from MiniTest::Test like this: require "minitest/autorun" class TestMe < Minitest::Test def test_true_is_true assert "3".is_a_number? end end

Categories : Ruby

Do I have to install Ruby on my Apache server to run scripts
You can probably run the script on your notebook directly. Try creating an example script like this: echo "puts 'hello'" > example.rb ruby example.rb That should print: hello You can run any Ruby code that way. You can also make the script executable. Edit example.rb so it reads like this: #!/usr/bin/env ruby puts 'hello' Then on the command line, make the script executable: chm

Categories : Ruby

Ruby: Does Test::Unit still exist?
Minitest is the new name for Test::Unit. It is fully compatible. Your syntax will still work for assert_equal, You do need to put the code into a test case.' Example: require "minitest/autorun" class TestMe < Minitest::Test def test_foo # test methods must begin with "test_" assert_equal 1, 1 end end

Categories : Ruby

How do I make a form that changes color with input text in Ruby?
You could do this with CSS and javascript. You could have a class background-color-blue with background-color: blue for example on your body or custom element. Then, when submit is clicked, you simply change the class to background-color-red. document.getElementById("MyElement").className = "background-color-red"; I would do some research using google/stackoverflow on how to change an elements

Categories : Ruby

compose objects without initializing objects that are not in hash
Your question raises some interesting issues. I will try to explain how you can fix it, but, as @Uri mentions, there may be better ways to address your problem. I've assumed @tranfee is to be set equal to the first value in the hash whose key begins with "tran" and that @rate is to be set equal to the first value in the hash whose key begins with "rate". If that interpretation is not correct, ple

Categories : Ruby

Undefined local variable or method in Rspec test?
You have a typo in your last test, you forgot the word do: it "has attack action" do expect(hero.actions[:attack]).to eq(attack_action) end Everything passes once added.

Categories : Ruby

How to enable Rubocop with Syntastic Vim plugin and Rbenv?
Syntastic is loading the wrong version of Ruby. From your command line, enter ruby -v && which ruby. Now, change the second line of the settings to: let g:syntastic_ruby_rubocop_exec = '/Users/jjasonclark/.rbenv/shims/ruby /Users/jjasonclark/yourprojectname/bin/rubocop' Using whatever paths which ruby and which rubocop show you.

Categories : Ruby

package.json (javascript npm) or requirements.txt (python pip) equivalent for ruby
Well, Which programming language has the best package manager? | Continuous Updating as well as the two SO questions linked in my question all point to Bundler: The best way to manage a Ruby application's gems. I guess the workflow is gem install bundler, add gems to Gemfile, then bundle install.

Categories : Ruby

Word Count (Ruby)
Hm, s = "Never eat shredded wheat" puts s.split.count # => 4 If you don't want to count underscores and digits: s = "Never eat shredded wheat 1 _ ?" puts s.split.reject { |w| w =~ /(W|_|d)/ }.count # => 4 even more advanced regexp: s = "Never __ 111 ?? eat shredded wheat. _Word?" p s.split.reject { |w| w !~ /([a-zA-Z]+(_[a-zA-Z]+)*)/ } # => ["Never", "eat", "shredded", "wheat.", "_

Categories : Ruby

How do I get my parser atom to terminate inside a rule including optional spaces?
The subexpression rule should first try to match the bool_operation rule before moving to value. rule(:subexpression) {(bool_operation | value).repeat(1)} Also, you need to tag the values in bool_operation so that they don't get incorrectly merged. rule(:bool_operation) { value.as(:first) >> bool_comparison >> value.as(:second) }

Categories : Ruby

CSV objects in Ruby. What are they exactly?
map works on any object that includes the Enumerable mixin. In order to work with Enumerable, the class needs to provide each - that's the foundation all the other nice methods are built on. Objects of the CSV class fit this pattern, as you can see in the documentation for the class. (The reason it doesn't push it straight into an array is because it's nice to be able to read the input file line

Categories : Ruby

Rails+ActiveAdmin - filtering with ransacker throws an error PG::SyntaxError: ERROR: syntax error at or near ","
So I found the solution: First, I've changed my filter in admin/account.rb from filter :by_active_projects_eq to filter :by_active_projects_in, :as => :string This approach resulted in correct SQL generation, "accounts"."id" IN ('e4d247ec-e64d-4e8a-996a-4d73ccb11257', 'bcb8fa61-4a53-4b45-8954-8fb6ae328365', '93d670b6-7b8f-4c27-91cc-e0f44c137114') After that I also had to cha

Categories : Ruby

Web starter kit installation Error
I also got a few errors upon installing via the npm install command, but in order to get it to go away I relaunched command prompt in administrator mode. It solved the problem easily. Hope it helps!

Categories : Ruby

How can I override Hash native brackets ([] access)
class Hash def [] key value = fetch key rescue case key when Symbol then "#{value}, as usual" when String then "#{value}, hooray!" else value end end end

Categories : Ruby

Amazon S3 secure URL at the bucket level
When you create a pre-signed URL, that is done completely locally. You could do it "by yourself", but it is much easier to use the SDK, and there would be no practical diferences. See that there is no "sign" action on the S3 API. However, you can not sign at the "bucket level", as signature is checked per-object. I believe signing a whole bucket would not be feasible.

Categories : Ruby

Tagging exceptions in Ruby, an explanation/alternative
Object#extend adds the instance methods of one or more modules, to the receiver object. So when you do error.extend(AcmeHttp::Error) you are actually adding the instance methods of the AcmeHttp::Error module to error which is an exception (actually a class object).

Categories : Ruby

Two thirds histogram Ruby
Your question is unclear. This? a = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10] tab1 = proc { Hash[a.group_by{ |v| v }.map{ |k, v| [k, v.size] }] } t1 = Thread.new(&tab1) t2 = Thread.new(&tab1) p t1.value p t2.value

Categories : Ruby

Combining words in a string into anagrams using ruby
As commented by Yevgeniy Anfilofyev , values is a method and hence it Returns a new array populated with the values from hash While, if we remove the method values then we get the whole hash and not only the array of values.

Categories : Ruby

Ruby SHA2 digest incorrect doc or issue in my IRB?
Seems like there is a typo in docs, look, block_length → Integer Returns the block length of the digest in bytes. Digest::SHA256.new.digest_length * 8 # => 512 Digest::SHA384.new.digest_length * 8 # => 1024 Digest::SHA512.new.digest_length * 8 # => 1024 digest_length → Integer Returns the length of the hash value of the digest in bytes. Digest::SHA256.new.digest_length * 8 # =>

Categories : Ruby

Regular expressions in Ruby with special characters
if you already know you're always splitting on the same character, you can just provide the character as a string: > "John Doe+123456".split('+') # no regular expression needed => ["John Doe", "123456"] or if you have to use a regular expression, then escape the + with a : > "John Doe+123456".split(/+/) # using a regular expression; escape the + => ["John Doe", "12345

Categories : Ruby

How to create a case insensitive Regexp from a non-case insensitive Regexp?
To add the case-insensitive "ignore case" option on the fly: original = /abc/ insensitive = Regexp.new( original.source, original.options | Regexp::IGNORECASE) To make the match case-insensitive without using the "ignore case" option, a possible solution is to create a regexp that matches uppercase letters and lowercase letter like this: original = /abc/ insen

Categories : Ruby

Converting string to date with Ruby
Remove the period from my_string and from the date pattern. Date.strptime(my_string.sub('.', ''), '%d %b %Y') That's assuming you have at most one dot in my_string. If there may be several, use gsub. Date.strptime(my_string.gsub('.', ''), '%d %b %Y')

Categories : Ruby

How can i iterate data through yml file until last data?
To iterate over a few arrays at once, you can use zip: def enter_data(doc) names, cities, checks = doc['samplepage'].values names.zip(cities, checks).each do |name, city, check| self.sample_name = name # related data self.sample_city = city # related data self.check = check # related data add # added it end submit end

Categories : Ruby

Can't understand this Ruby Hashes num Code
1) what does '|num| output' mean? this doesn't mean anything. ON the first line you declare that output is a string. the << operator append the value to a string. IN your case " RUBY#{num}" Is appendeds to the string. at the end you return the string by calling output which returns the value of the string. 2) why does the countdown number appear in the #{|num|}!? You interpolated

Categories : Ruby

How to pass a variable to Ruby through Ajax?
Try using toJSON to turn the data into a json string, then when you receive it in your ruby code you can use JSON.parse(data)

Categories : Ruby

Very simple DSL in Ruby
There're many different ways in which you can implement something like this. To keep it simple, you can just evaluate the block within a new Screen object and return the result. class Screen attr_reader :texts def initialize @texts = [] end def label(hash) # Validation + check for other keys texts << hash[:text] end def to_s texts.join end def self.write(

Categories : Ruby

Ruby: using .send within a method behaves differently than calling it outside
The problem is the line tags ||= %w(person city country other). It doesn't get (re)assigned, because tags will be an empty Array ([]) and not nil. Possible solutions are just taking an default argument of nil and passing in an Array or checking if tags is empty.

Categories : Ruby

How does Ruby's #count method deal with nil values?
You can write def my_count(*args) and check then length of args. I'd write: module Enumerable def my_count(*args) case when args.size > 1 raise ArgumentError when args.size == 1 value = args.first reduce(0) { |acc, x| value == x ? acc + 1 : acc } when block_given? reduce(0) { |acc, x| yield(x) ? acc + 1 : acc } else reduce(0) { |acc, x| acc +

Categories : Ruby

how to ensure irb accepts emoji input instead of escaping it?
Make sure Ruby is compiled with GNU Readline. When rvm compiles Ruby it automatically checks if Readline is installed, and if it is it will be included automatically. You can check your Readline version in irb. Example: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux] irb(main):001:0> Readline::VERSION => "6.3" So, copying your solution for installing the latest Readline with Ho

Categories : Ruby

How can I use pageobject navigation routes when I have multiple methods with parameters?
Here's an example from PageObject::PageFactory where Cheezy passes an argument to a method as part of his routes definition: PageObject::PageFactory.routes = { :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]], :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]] } The problem is, of course, that you don't have that argum

Categories : Ruby

How to load file in object context
instance_eval can take a String as its argument instead of a block, so rather than load (which as you suggest will load the file in the top level) you need to read the file contents into a string to pass in, something like: env.instance_eval(File.read(file))

Categories : Ruby

Ruby: File dialog wont close
I solved it by creating a new window with a button to open the file dialog. Upon clicking the open button, I also send a signal to destroy the main window. This way everything closes immediatly after I selected a file. For reference see this example

Categories : Ruby


Recently Add
'on raise' hook in ruby
Ruby OCI8 - bind optional parameters to Oracle Stored procedure
How to install the app only once for the suite
Different test unit output in Rubymine and console
Can Rake run each test in a separate Ruby instance?
Ruby strftime in UK format i.e. dd/mm/yy
Accessing hash in Ruby like objects in Coffeescript
How do I correct my script, that it doesn't matter what file name has the .xml that is uploaded?
Ruby: Tests not runing
Do I have to install Ruby on my Apache server to run scripts
Ruby: Does Test::Unit still exist?
How do I make a form that changes color with input text in Ruby?
compose objects without initializing objects that are not in hash
Undefined local variable or method in Rspec test?
How to enable Rubocop with Syntastic Vim plugin and Rbenv?
package.json (javascript npm) or requirements.txt (python pip) equivalent for ruby
Word Count (Ruby)
How do I get my parser atom to terminate inside a rule including optional spaces?
CSV objects in Ruby. What are they exactly?
Rails+ActiveAdmin - filtering with ransacker throws an error PG::SyntaxError: ERROR: syntax error at or near ","
Web starter kit installation Error
How can I override Hash native brackets ([] access)
Amazon S3 secure URL at the bucket level
Tagging exceptions in Ruby, an explanation/alternative
Two thirds histogram Ruby
Combining words in a string into anagrams using ruby
Ruby SHA2 digest incorrect doc or issue in my IRB?
Regular expressions in Ruby with special characters
How to create a case insensitive Regexp from a non-case insensitive Regexp?
Converting string to date with Ruby
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.