petitviolet blog

    ruby (8 posts)

    icon
    Written by petitviolet

    Make Thread synchronous in Rspec

    2021-09-25Ruby
    Stop using sleep to wait for asynchronous execution run on another Thread in Rspec
    tl;dr ruby allow(Thread).to receive(:new).and_yield What's the problem? In Ruby, Thread can be used for asynchronous processings that would take a while. However, the asynchronousity sometimes cause unexpected results in unit tests, like Rspec. Say, a class that uses Thread inte

    allow_any_instance_of to count up number of method calls behind the scene

    2021-08-25Ruby
    Rspec offers allow_any_instance_of to stub any instances that matches given class
    Rspec is one of the most popular test framework in Ruby, and of course it offers lots of functionalities for being able to write various type of test cases, like mock, stub, matcher, etc. allow_any_instance_of is a powerful method, which is able to stub any instance of a class even though using i

    Ruby on Rails on YugabyteDB

    2020-07-13RubyDB
    How to use YugabyteDB as a backend storage of Ruby on Rails application.
    YugabyteDB is "The Leading High-Performance Distributed SQL Database". https://www.yugabyte.com/ It has been developed as an open source and called [Distributed SQL](https://blog.yugabyte.com/what-is-distributed-sql/). YugabyteDB is a Distributed SQL product, like Google Cloud Spanner which is

    Tiny compiler written in Ruby

    2020-06-20Ruby
    Build a tiny compiler for a toy programming language in Ruby
    As a software engineer's habit, I've implemented a toy programming language in Ruby for my learning. GitHub repository is [petitviolet/9cc-ruby](https://github.com/petitviolet/9cc-ruby.git). What it looks like Almost *basic* syntax is supported, and only int type is available. - use number

    Empower Pattern Matching in Ruby

    2020-04-10RubyFunctional Programming
    Quick overview of pattern match in Ruby and Gems to empower it
    Ruby2.7 provides Pattern Matching feature as an experimental one. https://www.ruby-lang.org/en/news/2019/12/25/ruby-2-7-0-released/ I used to do pattern matching in Scala, so I'm excited to be able to use it in Ruby! tl;dr [Rstructural Gem](https://github.com/petitviolet/rstructural) what I'

    Circuit Breaker in Ruby

    2020-04-16RubyFunctional Programming
    Introduction of Circuit Breaker and RCB gem I developed
    I've developed a circuit breaker in Ruby, and published it as rcb gem in RubyGems.org. - GitHub: [petitviolet/rcb](https://github.com/petitviolet/rcb) - RubyGems: [rcb](https://rubygems.org/gems/rcb) What is CircuitBreaker? CircuitBreaker is a well-known pattern to make services stable that

    Imported blogs from Qiita

    2020-03-28QiitaRuby
    Download my contents and tranform into Gatsby style
    Qiita began to provide a feature to show what types of articles I write and put +1. At that time, they made when I read public without opt-in. [ユーザーページをリニューアルしました - Qiita Blog](https://blog.qiita.com/user-page-renewal/) I'd like not to make my browsing histories public, so I was going to delete my

    TeXを監視して自動コンパイルする

    2015-01-05QiitaRubyTeX
    rubyのguard/guardを使ってファイルの変更を監視して、裏で自動コンパ
    ruby の[guard/guard](https://github.com/guard/guard)を使ってファイルの変更を監視して、 裏で自動コンパイルする 準備 まずguardをインストールする 以下の様な Gemfile を用意する Gemfile source 'http://rubygems.org' gem 'guard' gem 'guard-shell' gem 'rb-readline' gem 'rb-inotify' そして sh gem install bundle bundle install でguard