Ruby

Consuming Tumblr blog from your website using Ruby on Rails (Spree), Backbone and Tumblr Api You need to have an account on tumblr of course and generate the application to be able to consume the tumblr api: http://www.tumblr.com/oauth/apps About the default callback you can choose any url for example: http:://localhost:3000 Then generate the application oauth in the following url: https://api.tumblr.com/console/calls/user/info Add the following gem to your Gemfile: [ruby] gem 'tumblr_client' [/ruby]

[ruby] namespace :banners do desc 'Populate default banners for homepage' task :populate => :environment do banner = Spree::BannerBox.find_by(category: 'box-1') unless banner 14.times do |x| box = "box-#{ x + 1 }" banner_values = { alt_text: '', url: '', category: box, banner_type: 'photo', enabled: true } banner = Spree::BannerBox.new(banner_values) banner.attachment = File.open(File.join(Rails.root, "app/assets/images/home/#{ box }.png")) banner.save! end # boxes type text 5.times do |box| box_category = "box-#{ box + 1 }-text" banner_values = { alt_text: '', url: '', banner_type: 'text', category: box_category, enabled: true } banner = Spree::BannerBox.new(banner_values) banner.attachment = File.open(File.join(Rails.root, "app/assets/images/home/#{ box_category }.png")) banner.save! end end end end [/ruby]

Hey there, Here you can find some examples using regular expression if you want to test your own regular expression you could use the following website to do it: http://rubular.com/ Regular expresion if you want for example match a exact word and that word is inside a full sentence sometimes and sometimes the first word or sometimes is the last word in the sentence you could use the following expression to get the correct matches: [ruby] ( |^)404( |$) or (^|\s)404(\s|$) [/ruby]

Hello guys, when you are working at crowdint.com, one of the most appreciated skills in a developer is when you enjoy to refactor your code all the time and in this little example I'm will share with all of you, about how to stop or avoid using if else conditionals in Ruby, so let's start.

Before the refactor
[ruby]
class Calculator
  attr_accessor :number_one, :number_two
  def initialize number_one, number_two
    @number_one = number_one
    @number_two = number_two
  end

 def calculate
   if @number_one == 5 and @number_two == 8
     puts "Are equal to 5 and 8: #{@number_one} and #{@number_two}"
   else
     puts "Are different to 5 and 8: #{@number_one} and #{@number_two}"
   end
 end

end
calculator = Calculator.new 5, 8
calculator.calculate
[/ruby]


My test file content: [ruby] describe ProductsService do describe '#valid?' do context 'when is successfully' do let(:result) { mock 'Result', object: {'errors' => ''}} before do subject.instance_variable_set(:@result, result) end specify do expect(subject.valid?).to be_true end end context 'when there is an error' do let(:result) { mock 'Result', object: {'errors' => 'error example'}} before do subject.instance_variable_set(:@result, result) end specify do expect(subject.valid?).to be_false end end end [/ruby]

Hola que tal, en este tutorial vamos a realizar un ejercicio muy pero muy basico, el cual consta de hacer una clase para sumar y restar y hacerlo con pruebas utilizando rspec. Para empezar lo primero que tenemos que hacer es crear nuestro archivo Gemfile para poder utilizar la gema de rspec con ruby para ello el contenido es el siguiente: Archivo Gemfile