I want to define a function in Rails Console

It's a little thing.

[Settings you want to make to copy the code to pry # Method 1: Make it a single expression ](Settings you want to make to copy the code to pry)

Line breaks will be ignored if enclosed in parentheses. It is ignored or considered in the middle of the expression until it closes.

A common pattern is when you want to define a function only while Console is up. I do this when I want to lightly test some of the methods.

In the Console


[1] pry(main)> (
[1] pry(main)*   def hoge
[1] pry(main)*     return 'hoge' #Processing content
[1] pry(main)*   end  
[1] pry(main)* )  
=> :hoge


[2] pry(main)> hoge #call
=> "hoge"

It's like that.

Recommended Posts

I want to define a function in Rails Console
I want to use a little icon in Rails
I want to add a browsing function with ruby on rails
How to make a follow function in Rails
[Rails] I want to send data of different models in a form
"Teacher, I want to implement a login function in Spring" ① Hello World
I want to click a GoogleMap pin in RSpec
I want to add a delete function to the comment function
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
Add a search function in Rails.
I want to find a relative path in a situation using Path
I want to implement a product information editing function ~ part1 ~
I want to make a function with kotlin and java!
I want to create a form to select the [Rails] category
A story I was addicted to in Rails validation settings
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to create a Parquet file even in Ruby
[Rails] I want to display the link destination of link_to in a separate tab
I want to develop a web application!
[Rails] A simple way to implement a self-introduction function in your profile
I tried to implement Ajax processing of like function in Rails
I want to write a nice build.gradle
How to insert a video in Rails
[Ruby] I want to put an array in a variable. I want to convert to an array
I want to write a unit test!
Steps to set a favicon in Rails
I want to add devise in Rails, but I can't bundle install
I want to use @Autowired in Servlet
I tried to make a group function (bulletin board) with Rails
I want to select multiple items with a custom layout in Dialog
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
I want to display a PDF in Chinese (Korean) with thin reports
I want to ForEach an array with a Lambda expression in Java
I want to send an email in Java.
I tried to organize the session in Rails
I want to use arrow notation in Ruby
Add a tag function to Rails. Use acts-as-taggable-on
[Ruby] I want to do a method jump!
I want to pass APP_HOME to logback in Gradle
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I want to simply write a repeating string
[Rails] I made a draft function using enum
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
How to implement a like feature in Rails
How to easily create a pull-down in Rails
I want to play with Firestore from Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
[Rails] I want to load CSS with webpacker
I want to get the value in Ruby
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
I want to be able to read a file using refile with administrate [rails6]
Rails6 I want to make an array of values with a check box
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
I want to call a method of another class
How to implement a like feature in Ajax in Rails
I want to do something like "cls" in Java
I want to embed any TraceId in the log